I am trying to import some Photos from a Facebook page that I own.
I am following this answer on Stack Overflow, more specifically the Client-Side part.
In the answer 3 steps are suggested.
Add the javascript SDK , which i do.
Something about Authentication but the link is wrong...
A piece of code for rendering the photos.
I skipped the 2nd step , cause I am not sure what to do there and I implemented the code in 3rd step :
FB.api('593959083958735/photos', function(response) {
if(!response || response.error) {
// render error
alert("Noo!!");
} else {
// render photos
alert("Yeah! " + response.status);
}
From here I get the alert "Yeah! undefined". The response is always undefined. I think maybe because I should have done something in the authentication part.
All I am trying to do here , is to import some photos from a public Facebook page. Is this the correct way to do that? If yes why would I need any authentication for it. And what exactly should I do in the authentication part?
From here I get the alert "Yeah! undefined". The response is always undefined. I think maybe because I should have done something in the authentication part.
You are querying the photos from a page, so there is no status field in the response.
All I am trying to do here , is to import some photos from a public Facebook page. Is this the correct way to do that? If yes why would I need any authentication for it.
You don’t need authentication for that – as you can see here in the Graph API Explorer, you get results even without an access token (after clearing the field). And you can see the structure of the response there as well.
Related
For some reason; I get error when trying to get my calendar events through google API. I code in JS and use React and have no idea why it does not work.
I have the token stored in sessionStorage and do get personal information about the user like name email and such stuff but I cannot proceed and get the calendar events. Please help!
I'm not sure what exactly you would like to see inside my App but let me know and I'll provide with the stuff because I do not want to upload the whole project lol
https://gyazo.com/37433e19f07e441adf368d1bbcad78e6
Maybe try to return res.send as you use async/await and it returns promise
I changed the structure of the app and I do now receive cal events when I hit one of my endpoints, but receiving other kind of error now, anyway this one can be closed.
Cross-origin request blocked, origin 'null' no access
I simply need to get the newest post from a specific Facebook page as a string in JavaScript for a website. I have never used the Facebook API and I'm still new to JavaScript, after many attempts I just can't figure out what the problem is...
So far this is everything I've done:
Created a Facebook app, chose 'website' for the platform
Inserted the JavaScript SDK code that I got from Facebook into my website code and replaced the placeholder 'appID' with the 'App ID' from my Facebook app
Became admin to the Facebook Page
On the Graph API Explorer page used the 'Get Token' dropdown to select 'Get Page Access Token', then selected the Facebook Page that shows up in the dropdown
Used the following request in the Graph API Explorer: 'https://www.facebook.com/pagenamehere/?fields=posts.limit(1)' (The output provides the post I need but with some extra information like "create_time", "id", etc. that I will most likely remove in JavaScript unless there is a more precise request I can use instead since I only need "message")
Copied the provided JavaScript code from 'Get Code' and inserted this under the JavaScript SDK code
replaced '//Insert your code here' with 'alert (response)', the alert message is: [object Object]
Either I don't know how to obtain "message" from '[object Object]', or I'm not getting the response I need. I've tried to do this with the webpage on a live server.
Please help, I'm out of ideas and I've read the Facebook API too many times.
Thanks in advance.
It's simple. Just have a look at the Graph API Explorer, and you'll get the idea how to access the message property:
Sample Graph API Explorer call
A call to /buzzfeed/feed?limit=1 will return
{
"data": [
{
"message": "science",
"created_time": "2015-11-23T07:01:00+0000",
"id": "21898300328_10154109572045329"
}
],
"paging": {
"previous": "https://graph.facebook.com/v2.5/21898300328/feed?limit=1&format=json&since=1448262060&access_token=&__paging_token=&__previous=1",
"next": "https://graph.facebook.com/v2.5/21898300328/feed?limit=1&format=json&access_token=&until=1448262060&__paging_token="
}
}
which means that
console.log(JSON.stringify(response.data.message));
should print you the message.
Thank you for your suggestions, they helped point me in the right direction and I was able to get this to work.
Here are the missing steps from my original post required to make it work:
Had to also add my domain to the 'Valid OAuth redirect URIs' field in 'My Apps' -> 'Settings' -> 'Advanced'
My access token had to be included in the code generated from the Graph API Explorer, like the answer in this post:
(your user access token should be extended to 60 days in the 'Access Token Tool' page by clicking 'debug' -> 'Extend Access Token' and using this token in the code)
The Facebook SDK needs to finish loading before the code generated from the Graph API Explorer is executed, I used Mohammed Arif's answer from this question to do this but I had to use a delay for it to work. I put his code in a function that runs after a 200ms setTimeout, if it is loaded the code generated from the Graph API Explorer executes, else I run the function after a 200ms setTimeout again.
Tobi's answer to part of the question (to get the message) was almost correct: response.data[0].message;
I am encountering a weird issue when trying to do an advanced login flow using the Facebook API with long-lived tokens stored on my server (https://developers.facebook.com/docs/facebook-login/access-tokens#long-via-code)
The issue is this: Upon shipping a generated code back to my client (a JS web app in this case) I should be calling the graph API to generate a long-lived token. My call looks something like this:
var requestUri = "/oauth/access_token?code=" + code + "&client_id=" + facebookAppId + "&redirect_uri=" + redirectUrl;
FB.api(requestUri, function(response) {
console.log(response);
});
However, upon callback of this FB.api request, I get a response that looks like the following:
{
"error": {
"message": "unknown error",
"type": "http"
}
}
There is also a JS error in the console:
Uncaught SyntaxError: Unexpected token :
What is really strange about all of this is that if I look at the raw response of the call to /oauth/access_token I see the expected response with a 200 success code
{
"access_token": "...",
"machine_id": "...",
"expires_in": 5184000
}
I can determine from this that the JSON response isn't be read correctly by my browser (Chrome in this case). In fact if I paste the raw response above into Chrome Dev JS Console, it gives me the same JS error. However, if I were to assign it to a variable in the console, there are no problems. It basically seems as though something is going wrong in Facebook's JS SDK and the response object never is properly returned to the callback function. Has anyone encountered anything like this before? I can't seem to find an answer for this.
I did find a workaround for this for the time being. I'm pretty sure the problem stems from somewhere in the Facebook JS SDK. To get around this, I made a raw call using AJAX to the graph API, in this case using AngularJS
$http.get("https://graph.facebook.com/oauth/access_token....)
This way, I can get the response I need without having to deal with an error that I can't get to.
I can also get away with not using FB.api because I am requesting an access token and don't need to worry about the JS SDK managing it for me.
If anyone has any other solutions to the initial problem, I would be delighted to hear them. I still would like to use Facebook SDK wherever possible.
As part of a project whose aim is to notably improve the visual side of a SharePoint Online site, I'm a bit stuck. On the home page in the left banner, users want to see the number of unread messages they have in Office365.
I created an area in the master page to put the result in. I thought the Rest API used to do this :
$.ajax ({
type: "GET",
url: " https://outlook.office365.com/ews/odata/Me/Folders/Inbox",
dataType : "json",
success : function (resp) {
// count unread messages
},
error : function (e) {
alert (' Error121212 :' + JSON.stringify (e));
}
})
Unfortunately I get an error like cross domain. I tried with JSONP but it does not work either (uncaught syntax error unexpected token).
Can you please tell me if this is a good practice? I feel that it anyways I must find a technic for authentication. (In the case of JSONP I have a popup that asks me authentication and then problem occurs on callback apparently)...
I want to avoid developing a type requiring a typical deployment Wsp...
Thank you in advance for your help.
Your URL for the ajax request seems incorrect. The URL for getting the inbox messages via the API is: https://outlook.office365.com/api/v1.0/me/folders/inbox/messages
Once you get the response, you can count the number of objects with the IsRead property set to false using a simple for loop and display that count.
The issue here is related to CORS and how browsers refuse to handle cross-domain requests. To get around this, typically you would either
Change the response header on the remote server - not an option here
Use some sort of proxy to handle the requests - here's where SharePoint apps come in.
I know you stipulated that you want to avoid using a WSP style deployment but there simply isn't a way around it, you have to use the SharePoint App Model
This article goes a long way to answer your question, but for completion the basic steps are as follows
Create a SharePoint hosted app in Visual Studio
In the App Manifest, you need to define the trust relationship with the remote host (in this case the host of outlook.office365.com) using the AppManifest section
Use SP.RequestExecutor.executor to make the request on your behalf
I'm currently developing a little Website with Firebase. I got a couple of HTML files and each file contains a logout button which calls the function
function logout(){
auth.logout();
console.log("logout successfull");
location.href="index.html";
}
After getting redirected I tried to login again but it always failed with the following error message:
Error: FirebaseSimpleLogin: An unknown server error occurred.
It took me some time to realise that the redirection to the index page caused the problem. When I delte the location.href="index.html"; line, everything works fine.
Problem is, I really need something that redirects me to the front page, when the user isn´t loged in. Is this a known problem and/or can someone come up with a solution to this problem?
Thanks in advance :)
PS.: I realised that I could "fix" the problem (after getting redirected to the index page) when I cause an error (f.e. calling a undefined function). Idk if this information helps...
Ok, thanks for your reply Kato!
I changed quite a lot, since I started the "project". Instead of using mutliple HTML files I copied everything into the index.html and work now with mutliple (hidden) DIVs.
But unfortunatly, the problem still exists.
I offer two different Login possibilites. One with Facebook (works 100% of the time for me) and one with the SimpleLogin (works barely).
I´m pretty sure I did the initialization the same way like it´s done in the tutorials on firebase.com.
This is how I connect to the Firebase DB
var ref = new Firebase('https://partyfinder-db.firebaseio.com/');
var auth = new FirebaseSimpleLogin(ref, function(error, user) {
if (error) {
// an error occurred while attempting login
alert(error);
} else if (user) {
// Here I work with user.id etc.
} else {
// user is logged out
}
});
And that is how I try to login the user...
function login() {
//I probably should use jQuery here...
var _email = document.getElementById("emailLogin").value;
var _pw1 = document.getElementById("passwordLogin").value;
var _rememberMe = document.getElementById("rememberMe").checked;
auth.login('password', {
email: _email,
password: _pw1,
rememberMe: _rememberMe
});
showMain(); //Hide and show DIVs and stuff...
}
I call this function on the SignIn Button. The whole Javascript file is linked in the head part of the HTML file.
So, calling this function is normally causing the following error
Error: FirebaseSimpleLogin: An unknown server error occurred.
I already figured out that this message only shows up when the connection to the DB already was successful. For example, when I type in an invalide email adress, the following message appears:
Error: FirebaseSimpleLogin: The specified user does not exist.
There are a few things that can "fix" the problem. For example, when I use the Facebook Login and logout after this was successful, I can sign in using firebase simpleLogin. Sometimes (unfortunatly not always) it helps when I`m causing an error, f.e. calling a non existing function. After the error message is displayed in the console, I can continue logging in (successfully).
But to be honest I`ve absolutly no idea what this tells me about the error and if this is somehow a hint to the solution. I also tried to set some breaking points and debug through the relevant code (using google chrome) but didn´t find anything.
I uploaded the page to a free webspace, where you can test this whole thing by yourself.
But please note, this project is just for testing purpos. I´m not planning to release it somehow, it´s just for me to figure out multiple things and I find it easier to learn something when I can set it in a context. I´m pretty sure it´s quite bad coded and contains many mistakes, etc. But I´m always grateful for feedback beside the actual problem :)
For the login you can use
email: user#email.com
password: user
If you use the FB-Login, your Name and your email adress will be saved to the Database (but I can delete this section of the code if you want/need to use it and feel uncomfortable about it).
http://partyfinder.lima-city.de/
Most of the comments are in german, sorry for that...