Well, I have one website where i'm using the Facebook Plugin (the typical box with your followers and posts)...How i can showing the Facebook Rating in the same box? I'm not found the option :S
It's this possible?
Thanks for help me! And sorry for my English ;)
Edit:
Thanks for the URL's in i'm found one example and i'm editing this. I've the following code:
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/1447162575539510/ratings', function(response) {
if (response && response.error){
console.log("ERROR: "+response.error.message);
}else{
console.log("RESPONSE: "+response.open_graph_story);
//console.log('Successful login for: ' + response.rating);
document.getElementById('status').innerHTML ='Thanks for logging in, ' + response.name + '!';
}
});
//FB.api("/410442505719113/ratings",function(response){
//if (response && !response.error){
//console.log(response.name);
//}else{
//console.log("ERROR : "+response.error.message);
//}
//});
}
But always give me the same error: ERROR: (#210) Subject must be a page. And i don't know for why, the profile is a page in facebook
HereĀ“s what you have to do:
Create a Facebook App
Authorize a page admin with the manage_pages permission
Extend the User Access Token (from 2h to 60 days)
User /me/accounts with that Token to get an Extended Page Access Token
User /{page-id}/ratings with that Page Token to get the ratings
Some links for you, covering all those todos:
https://developers.facebook.com/
https://developers.facebook.com/docs/facebook-login/access-tokens
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/accounts
https://developers.facebook.com/docs/graph-api/reference/v2.1/page/ratings
http://www.devils-heaven.com/facebook-access-tokens/
Related
I've looked everywhere to find an example code that checks if the current user has liked a facebook page WITH authorization using access_token.
Here is the code I usually come across which I've tried and still didn't work:
FB.api("/me/likes/{page-id}", 'GET', function(response) {
}
The output of that code is a json that is empty. How would I add a access_token to get permission of user_likes in a code such as that.
P.S. I've looked at the documentation for graph api and it's quite vague as there isn't any example of you would get authorization to see if a user likes a facebook page using Javascript.
I finally found how, I didn't embed my code in FB.login
FB.login(function(){
FB.api(
'/me/likes/{page-id}',
'GET',
function(response) {
if(response.data.length == 1){
alert('User has liked page');
}else{
alert('User hasn't liked page');
}
}
);
}, {scope: 'user_likes'});
I am stuck with access rights in trying to post on facebook company page.
I have created an application and gotten appId and secret.
I have linked the application to the existing facebook page.
I have retrieved an accessToken for the appId.
But get the response: "(#200) The user hasn't authorized the application to perform this action."
Which user does the error statement refer to? the AppId user? The administrators of the page (me)? And where can I grant these missing rights?
I am trying to achieve that the post functionality is not facebook-user-dependent, but is company (or appID) dependent.
I am really confused about this...
Off course we could create a bogus user (kept in the company files) and post as this user - but that goes against the Facebook policy, and that is not the road we want to go down...
function FB_doPost(link, message, accessToken) {
console.info('doPost');
FB.api('/pageid/feed', 'post', {
access_token: accessToken,
message: message,
link: link
}, function (response) { if (!response || response.error) { console.info('error occured: ' + response.error.message) } else { console.info(' post id: ' + response.id) }; }
);}
In order to post to a Page "as Page", you need to do the following:
Authorize a Page Admin with publish_pages and manage_pages
Use the /me/accounts endpoint to get a Page Token for that Page
Use that Page Token with the /pageid/feed endpoint to post as Page
Make sure you know about the difference between Access Tokens, here are some links about that:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
I'm testing how all the facebook api calls work, and I need to know how it is possible to print user_friends on a page, after the user gives permission.
I wrote this code, in order to try and print the user_friends feilds:
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.user_friends + '!';
});
}
At the end, I added response.user_friends, however I don't get the user friends list printed on the page, instead I get "undefined".
If I change it to response.name, it work and the name of the user is printed.
P.S.
In the log in button I requested the user friends list:
<fb:login-button scope="public_profile,email,user_friends" onlogin="checkLoginState();">
</fb:login-button>
It is just a test for me to understand how the user_friends look like, I'm not going to do so in the actual app.
So Why I'm not getting the user_friends printed at the page?
Thanks
You have to authorize the user with the correct permission (user_friends) before making any API call. See those links for more information about user authorization with the JavaScript SDK:
https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.2
http://www.devils-heaven.com/facebook-javascript-sdk-login/
After that, you can use /me/friends to get the friends of the authorized user. Keep in mind that you can only get the friends who authorized the App too, for privacy reasons. More information about that can be found in the following thread: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app
I have created a custom story to be posted on facebook timeline when user clicks on a share button.
While i was logged into facebook, I could successfully post on timeline using the following code
function postLike() {
FB.api(
'https://graph.facebook.com/me/og_pricepan:compared',
'post',
{ product: objectToLike,
privacy: { 'value': 'SELF'}
},
function (response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
document.getElementById('result').innerHTML =
'<a href=\"https://www.facebook.com/me/activity/' +
response.id + '\">' +
'Story created. ID is ' +
response.id + '</a>';
}
}
);
Now, when the user is not logged into facebook, I get the following error:
Error: An active access token must be used to query information about the current user.
Shouldn't the login window get open by itself asking the user to login into facebook or I need to do something on my end to handle this situation?
Also, do i need to submit my application for review before users can create custom stories from my website to their timeline?
Shouldn't the login window get open by itself asking the user to login into facebook or I need to do something on my end to handle this situation?
No. You need to explicitly login the user by following the Facebook Login Flow to request an access token
Also, do i need to submit my application for review before users can create custom stories from my website to their timeline?
Yes and No. No, because it's not like you will have someone from Facebook Support Team going through your app to make sure your app ticks all the boxes. Yes, because you will need to register your app with Facebook. So, technically all you need to do is register with Facebook as a developer and register your app in order to get an app secret and API key. You can have your app in "Sandbox mode", create test users and test your integration with Facebook before you publish it live. There's few requirements you need to meet before publishing it, such as providing set of logos of a specific size, etc. Here's a blog explaining part of the process, but really, the process is very straight-forward and you should be able to get through easily by yourself.
Now, the error you are getting says it all. There's no user logged in to facebook. The endpoint you are trying to post to, requires a active valid access token, if it doesn't exist then there's no context, no user authenticated and you need to explicitly authenticate the user by invoking the login dialog...
FB.login(function(response) {
if (response.authResponse) {
// The person logged into your app
} else {
// The person cancelled the login dialog
}
});
If you need to know whether a user is logged in or not, you can follow to simple approaches:
1.By invoking the FB.getLoginStatus function
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
}
else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
}
else {
// the user isn't logged in to Facebook.
}
});
2.Or, by subscribing to the auth.authResponseChange event when initializing the framework and setting the status option to true
There's a full-legged tutorial on Facebook Developers Site for Javascript SDK explaining both approaches.
Hope it makes sense
I am wondering if it is possible to post through a Facebook app to an associated page as if the post was done on the page itself. I.e. if I am logged onto Facebook and I go to a page I am admin for, then when I post it will appear with the name of the page rather than my Facebook name. I would like to replicate this behaviour but coming from an external website connecting through a Facebook app. I have made all of the connections and I am able to post ok but it is coming through as my name. I am using the Javascript API with the following to login:
FB.login(function(response) {//do some login processing},
{scope: 'publish_stream'});
Then I publish the message with the following after logging in and accepting the permissions:
FB.api('/[PAGE NAME]/feed', 'post', { message: Text to post }, function(response) {
if (!response || response.error) {
alert('Error occurred '+response.error.message);
} else {
alert('Post ID: ' + response.id);
}
});
My Facebook App has the Site URL and App Domain set correctly and I have setup the App as a Page Tab and combined that to my page.
So if anyone can let me know if it is possible and how to do it, it would be greatly appreciated
Thanks
It's all about Authentication, you have a User Access Token but you need a Page Access Token to authenticate as a page.
Here is the doc: https://developers.facebook.com/docs/authentication/pages/