Trying to get localization keys to work with firebase and nodes firebase.admin utility but cannot get it to work.
I receive a messageId when sending and no errors at all so a little stuck.
I use a Firebase Function to send notifications so everything is running within firebase.
admin.messaging().sendToTopic("my_topic", {
"notification": {
"titleLocKey" : "FRXT",
"bodyLocKey" : "FRXB",
"bodyLocArgs" : "['test']"
}
}).then(function(resp){
res.send(200, resp)
})
I guess i'm doing something wrong here that i just cannot see so if there are any smart people out there please give a shout. The keys used are in the iOS localization string file. If i just use title and body the push work fine also.
Related
I am trying to use the Twitter API to tweet, retweet, and upload images, while tweet works as intended, upload media don't work. more information below
packages i use :
node-fetch
deepmerge - to merge the given options
oauth-1.0a
crypto
the error appears at all the fetch request related to this function
Error:
{ errors: [ { code: 32, message: 'Could not authenticate you.' } ] }
I know whats the error is about, just asking this as I am confused why this would appear only in this function,as the auth info is correct and the same function used to create the headers work in another function
some important functions and related : https://hastebin.com/eyepikidax.kotlin
the code affected : https://hastebin.com/inehomodag.js
tweet function : (the working function) : https://hastebin.com/xatebakahe.properties
even though the tweet works with the same function _makeRequest(custom function) uploadmedia dont
uploadmedia is same as tweet but with extra steps like uploading media
i logged the headers provided by _makeRequest for the tweet function and the upload function
headers: https://hastebin.com/xojotupine.rust
it seems in the uploadmedia function the headers became invalid but in the tweet function they are valid
The issue was with the authorization headers, I had to generate them for each request.It was easy as creating a wrapper function that will take the request details (the needed ones) and output the headers
I have a Twitter API library written in typescript (unmaintained for now :/ )
That uses this, don't suggest completely using that, just take what you need from it
Code Related
^^
Above Links to - https://github.com/typicalninja493/tweets.ts/blob/master/src/rest/bucket.ts#L200
I'm trying to fetch featured image from my published post but it seems impossible! I get
an error :( that's the code:
function fetchSlideShow(){
let endpoint = "http://loreleiheckmann.com/wordpress/wordpress/wp-json/wp/v2/Vinyls?_embed";
fetch(endpoint)
.then(e => e.json())
.then(showSlideShow);
}
function showSlideShow(data){
console.log(data);
data.forEach(showSingleSlide);
showSlides();
}
function showSingleSlide(aSlide) {
let template = document.querySelector(".slide_template").content;
let clone = template.cloneNode(true);
console.log(aSlide);
clone.querySelector("img").setAttribute("src", aSlide._embedded["wp:featuredmedia"]
[0].media_details.source_url);
let SlideList = document.querySelector("#SlideList");
SlideList.appendChild(clone);
}
While going to the array I see error 401 :( and moreover: Cannot read property 'source_url' of undefined" I don't know what I'm doing wrong .. any insights?
HERE ARE THE ERRORS -> 401 ON CONSOLE + PROBLEM WITH URL.:
Please try changing your url in the endpoint variable:
let endpoint = "http://loreleiheckmann.com/wordpress/wordpress/wp-json/wp/v2/posts?per_page=20&_embed=wp:featuredmedia
If you need more data you can add them with a comma:
wp-json/wp/v2/posts?per_page=20&_embed=wp:term,wp:featuredmedia
Post per page is optional, but I would prefer having that set.
And you should write what image size you need. That way rest api will give you the right source url:
_embedded['wp:featuredmedia']['0'].media_details.sizes.medium_large.source_url
I think it would also be better practice if you use an ssl certificate, there are free by "Let's encrypt".
EDIT:
Your screenshot shows the rest api message:
wp:featuredmedia: Array(1)
0:
code: "rest_forbidden"
data: {status: 401}
message: "Sorry, you are not allowed to do that."
So the 401 status code means: unauthorised
Seems like you are not allowed to access the data via rest api.
There could be multiple reasons for that:
The image is attached to an unpublished post. The post may have the status "private" or "draft", and therefore is not public available.
Your post (and attached image) is not available for not logged in users. If there is a restriction to view your code, this also applies to rest api.
Maybe you are using some kind of membership plugin that restricts the wp rest-api. Try deactivating all plugins if one of them affects the behaviour.
You have added some custom code to restrict access rest api access.
If nothing works for you, you should look into your database and check the medias post_status.
I think it is working fine, but you do not have access to view the posts data. This is what the 401 error indicates.
To whom it may concern - In the end, I added image in WP by custom post type ( I gave up wp:featured media - I wasn't able to fetch it.) Afterward I added a code to JS -> b.querySelector(".img").setAttribute("src", a.acf.image.url); so it works:)
I am trying to add an app to our SharePoint Online site using the template from https://learn.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part and we get the error below when we deploy to SharePoint and add the app/Web part to a test SharePoint site. We are using TypeScript as the template uses.
Has anyone else encountered this issue or know where to look for the issue?
Found [object Object]Driver Display External Error: Error: AADSTS500011: The resource principal named https://driverdisplayexternal.azurewebsites.net was not found in the tenant named 7018324c-9efd-4880-809d-b2e6bb1606b6. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant. Trace ID: 358b22eb-cd2c-4091-b592-5a57cbc21d00 Correlation ID: ec96d656-1a36-42e2-a2b9-3ff78efc1e2e Timestamp: 2019-10-01 16:26:06Z
We have added a call to our own client as shown below. We are not sure why the resource principal was not found. The Tenant ID's match and things seem to be set up properly for authentication.
HelloWorldWebPart.ts
...
this.context.aadHttpClientFactory
.getClient('https://driverdisplayexternal.azurewebsites.net')
.then((client: AadHttpClient): void => {
client
.get('https://driverdisplayexternal.azurewebsites.net/api/values', AadHttpClient.configurations.v1)
.then((response: HttpClientResponse): Promise < Order[] > => {
this.domElement.innerHTML += 'Received a response from Driver Display External: ' + response;
return response.json();
})
.catch(error => {
this.domElement.innerHTML += 'Driver Display External Error: ' + error;
console.error(error);
});
});
...
package-solution.json
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "helloworld-webpart-client-side-solution",
"id": "**ID**",
"version": "4.1.0.0",
"includeClientSideAssets": true,
"isDomainIsolated": false,
"webApiPermissionRequests": [
{
"resource": "DriverDisplayExternal",
"scope": "User.Read.All"
}
]
},
"paths": {
"zippedPackage": "solution/helloworld-webpart.sppkg"
}
}
Any help or direction to where the issue may be would be very appreciated. Thanks in advance!
Never used this API, but if I had to guess you need to change the value here:
.getClient('https://driverdisplayexternal.azurewebsites.net')
You can use either the client id / application id, or the application ID URI.
Sometimes this problem can occurr when you set a wrong name for the scope you are requesting access for or another configuration parameter.
I suggest to check carefully the scopes name, or maybe directly use the "copy" button from the Azure portal.
In my case it was a simple typo on a scope name.
Not sure if you figured the answer or not. When you used SPFx to request your own custom web api end point. there are couple steps:
request the permission so that you can go to SPO admin to approve the permission you request. for this case, the webApiPermissionRequests->resources needs to your AAD Application's Service Principal DisplayName. once you had AAD App create, you can run Get-AzureADServicePrincipal to get all your ServicePrincipal.
once you request the permission, from your code, you need to call AadHttpClient.getClient() to get aadHttpClient object based on the api resourceEndpoint you want, for this case, you need to pass your web api's Application ID URI which can be found from your AAD App's manifest->"identifierUris". General speaking, this should be something like api://[clientid] format. but you can change it to any unique value.
I hope it helps.
In my case i had to use the App Id when i was consuming a multi tenant API.
In my case, TenantId and ClientId were both ok.
They can be found in AAD. TenantId is right there on landing page:
and then on the same page click Applications then tab All Applications find your application there should be ClientId check if they match.
If that is still not enough, click on the application and find roles
For me, it was roles that were missing after adding those wheels started rolling again:
I'm testing some functions locally using my database created on parse.com and the functions run exactly as intended. I am trying now to put these functions on cloud code to reduce the amount of request sent to parse as well as run the queries in the cloud code instead of locally. For whatever reason I cant get these functions to work when I convert them to cloud code. Also, how would I make a button in html that can run a function in cloud code?
Before cloud code, my html button looked like this:
<button type="button" onclick="authenticate()">Log-In</button>
How would I create that button with cloud code that looks like this:
Parse.Cloud.define("authenticate()", function(request, response) {
var myname = document.getElementById("username").value;
var mypass = document.getElementById("psswd").value;
Parse.User.logIn(myname, mypass, {
success: function(user) {
// Do stuff after successful login.
if(myname == "test1" || myname == "test2"){
window.location.href="itSplash.html";
}
else{
window.location.href="ticketRequest.html";
}
},
error: function(user, error) {
// The login failed. Check error to see why.
alert("Failed to login: " + error.message);
}
});
});
for clarification that if statement just directs login to itSplash if username matches test1 or test2, and ticketRequest if its anyone else. We have a seperate page for different users. Also, that function works locally if I create it as a normal function authenticate(). When I converted it to cloud code as seen above it wont work. I create a seperate function name runAuthenticate() with a Parse.Cloud.run call inside that and it wouldnt work there. All I got was an Error saying define cannot be used on that Object. Any Help?
You can link the HTML button with a cloud code function by using Parse.Cloud.run.
Take a look at the Parse Cloud code
documentations.
This is how you can call the cloud code from javascript.
Parse.Cloud.run('hello', {}, {
success: function(result) {
// result is 'Hello world!'
},
error: function(error) {
// Error while running cloud code
}
});
As you have written, you can try calling a javascript method onclick on the HTML button and then call the Parse.Cloud.run method.
First, you don't have access to document or window in cloud code so you need to rethink where you're coming from.
Also, it isn't appropriate to have the user details sent to the cloud code, you should login on the web page using the SDK and then use the SDK to trigger the cloud code and it will send the user and auth details.
So, the whole premise of your authenticate function being in cloud code doesn't really work.
That doesn't mean you shouldn't use cloud code, it's just that you shouldn't use it for this purpose. You talk about making queries but you don't actually have any in the code you show - but that kind of thing is more likely to be movable to cloud code...
I have to integrate Sign-in-with Twitter in my app as below.
https://dev.twitter.com/docs/auth/sign-twitter
It is browser based app developed in JavaScript
I have been refering google code java script OAuth, but im confused how to use oauth/authenticate and how to get the oauth_token
Can any one please help me out with some samples ?
Problem with this is that anyone who views your page can also now view your consumer key and secret which must be kept private.
Now, someone could write an app that uses your app credentials and do naughty and bad things to the point that twitter and users ban you, and there isnt anything you can do.
Twitter do state that every possible effort must be made to keep these values private to avoid this happening
Unfortunately, there is currently no way to use oAuth in Browser based JavaScript securely.
Check out the Twitter #Anywhere JSDK authComplete and signOut events and callbacks at https://dev.twitter.com/docs/anywhere/welcome#login-signup
twttr.anywhere(function (T) {
T.bind("authComplete", function (e, user) {
// triggered when auth completed successfully
});
T.bind("signOut", function (e) {
// triggered when user logs out
});
});
Use below code in consumer.js and select example provider in index.html drop down list
consumer.example =
{ consumerKey : "your_app_key"
, consumerSecret: "your_app_secret"
, serviceProvider:
{ signatureMethod : "HMAC-SHA1"
, requestTokenURL : "https://twitter.com/oauth/request_token"
, userAuthorizationURL: "https://twitter.com/oauth/authorize"
, accessTokenURL : "https://twitter.com/oauth/access_token"
, echoURL : "http://localhost/oauth-provider/echo"
}
};
Since I was searching for the same thing, trying not to use a custom PHP solution, I came across this very simple integration at http://www.fullondesign.co.uk/coding/2516-how-use-twitter-oauth-1-1-javascriptjquery.htm which uses a PHP proxy that accepts whatever twitter api call you'd like to retrieve from your javascript ..
I'm definitely taking a look at it