So in my app, I do this:
FB.api('/me', function(response) {
alert(response.name);
});
This gives me the users name IF they are logged into FB through my site. Now, is there a way I can get a unique ID for them as well? That way everytime they post something on my site, I can store their post along with their FB name AND Id, and then I know which posts they have made in the past when they are connected to their FB through my site.
You can use response.id to get the Facebook Users unique id.
Related
I know how to make a post to a Facebook page via the API using PHP SDK, that is done like this:
$facebook->api('/xxxxxxxxxxx/feed', 'post', array('message'=> 'Hello world!', 'cb' => ''));
Where xxxxxxxxxxx is page id ;)
But doing that, I post to that page as me, Jamie, and not as the Page itself (admin).
So how do I post as Admin/Page instead of myself?
Thanks you for your time!
ANSWER (for lazy people):
First of all you need to make sure you have access to manage pages for user, ex:
<fb:login-button autologoutlink="true" perms="manage_pages"></fb:login-button>
Now you also gets a special token for every page user have access to once you get them.
PHP SDK Example:
//Get pages user id admin for
$fb_accounts = $facebook->api('/me/accounts');
//$fb_accounts is now an array
//holding all data on the pages user is admin for,
//we are interested in access_token
//We save the token for one of the pages into a variable
$access_token = $fb_accounts['data'][0]['access_token'];
//We can now update a Page as Admin
$facebook->api('/PAGE_ID/feed', 'post', array('message'=> 'Hello!', 'access_token' => $access_token, 'cb' => ''));
Check out this note regarding your question: http://developers.facebook.com/docs/api > Authorization > Page impersonation.
Long story short, you need the manage_pages extended permission.
And btw, have you checked this first ?
How can i get the user id from facebook url and get the basic info ?
This will be possible if i use the http://www.facebook.com/[username] '
In order to get the ID of a Facebook User, you need to authorize the User: https://developers.facebook.com/docs/facebook-login/
After that, you will get an "App Scoped ID" for that User with this API endpoint: https://graph.facebook.com/me?access_token=[user-token]
It is NOT possible to get the ID of a user by his username (or URL). Scraping is not allowed on Facebook - that i what some platforms do. But you do not need that ID anyway, you can just use the App Scoped ID instead.
i'm currently using the following api of FB Login integration in my Mobile Website : FB.api('/me', function(response){...} . In the resposnse i am only getting an id field and a name field. Is there any way where i can retrieve the actual email of the user who logs on to the site using FB Login pop up.
I read in the documentations about another URL /{id} , but it also returns only id and name.
Please suggest
To get the email of a user, you have to autorize the user with the email permission, and you have to add the field parameter to the API call:
FB.api('/me?fields=name,email', function(response){...}
or:
FB.api('/me', {fields: 'name,email'}, function(response){...}
Check out the changelog, about "Declarative Fields": https://developers.facebook.com/docs/apps/changelog#v2_4
I am using Facebook JS sdk to show news feeds. the app works well for many users for for some users who have authorized my app doesn't bring reasonable result.
I use following code to get basic profile info which works for some users but for some it doesn't:
FB.api('/' + id + '?access_token=' + access_token, function (response) {
var strTitle = response['first_name'] + " " + response['last_name'];
});
In response object I receive only id, birth date, email, profile link but name is not available. Interestingly when I open profile link in my browser facebook says:
"Sorry, this page isn't available
The link you followed may be broken, or the page may have been removed."
after that my code can bring its posts but again the from name of the posts is missing in response object. The permissions list is attached as picture.
I can't understand what is going on and how can i fix this issue. Any help please?
The problem is that you are using the App center permissions feature (previously known for Authenticated referrals).
Use these settings to enter the set of permissions your app requires when displayed in App Center
You should be passing a login url with the scope array of permissions in JS SDK.
FB.login(function(response) {
// handle the response
}, {scope: 'email,user_likes'});
or via a login button
<div class="fb-login-button" scope="email,user_likes" data-show-faces="true" data-max-rows="3">Login with Facebook</div
To post a photo to logged in user's photos these are the api function parameters:
$result = $facebook->api('/me/photos/', 'post', $attachment);
I would like to post a photo in offline mode using this:
$result = $facebook->api('/'.$user_id.'/photos/', 'post', $attachment);
But this does not work, because I think user_id is read as a album id.
What is the proper url for posting to user's photos when I have a user id?
Where can I find the list of all these "url"s for different graph actions?
Note:User has granted publish and offline permissions to the app.
As long as the token is active you can use me so $result = $facebook->api('/me/photos/', 'post', $attachment); should still work back when offline_access was possible. Even now with 2 month tokens you can use me, again as long as the access token is valid.