How to get User's avatar after Facebook API was changed - facebook

I have an issue the relates with Facebook API. Before, I can use the graph api like that to get user avatar
//graph.facebook.com/giuliana.roeffero/picture?type=large
But now I got this issue
{
"error": {
"message": "(#803) Cannot query users by their username (giuliana.roeffero)",
"type": "OAuthException",
"code": 803
}
}
So now, I need to use the User ID instead of User Name, like this
//graph.facebook.com/100001473111658/picture?type=large
And my question is Can we get the User Avatar by User Name via Facebook API now? If not, how can I get the User Id by User Name?

You can´t get the username at all, it was removed from the API. The only way is to use the (App Scoped) ID, just as you mentioned in your question. So this is how you get the Avatar:
Authorize the User (with no additional permissions) to get his App Scoped ID
use https://graph.facebook.com/[User-ID]/picture to get his Avatar

Related

Facebook API: Instagram Account Is Missing

whenever creating or updating an Ad's creative, I'm getting this error:
{
"error": {
"message": "Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_subcode": 1772103,
"is_transient": false,
"error_user_title": "Instagram Account Is Missing",
"error_user_msg": "You're using Instagram as a placement. Please select an Instagram account to represent your business in your Instagram ads, or select a Facebook Page to use instead.",
"fbtrace_id": "..."
}
}
However, what I simply try to do is to create an Ad for a specifc Page Post and add this to an existing AdSet. To create a new creative for a given Post, I use the /adcreatives endpoint and pass the following:
POST: https://graph.facebook.com/v3.1/act_<ActId>/adcreatives
{
"name": "Test",
"object_story_id":"<PostIdWithPage>",
}
This works fine so far. But the following update of the Ad results in the error above:
POST: https://graph.facebook.com/v3.1/<AdId>
{
"creative": {
"creative_id": "<CreativeId>",
}
}
I guess, the above error happens when I try to add a creative to the Ad that can not be used on Instagram.
But why isn't it working like in the Business Manager? There, I can simply select a Post for a newly created Ad. If this Post is not valid for Instagram, it shows a warning but it still works.
So, when I want to create a tool that can create Ads based on given Posts, how can I achieve that? How can we come around the error above?
The important missing part here is, that we have to specify instagram_actor_id when creating the AdCreative. The ID can be retrieved by GETting <PageId>/page_backed_instagram_accounts.
Further to the accepted answer, I needed a little bit more information to properly connect an instagram account to my page:
There are two ways to link in instagram account to your page:
1. Setup a 'Page Connected' instagram account
Log in as a page admin, go to page settings > instagram and link
an existing instagram account to the page.
You can then get the linked instagram account id by doing a GET on:
<PageId>/instagram_accounts
2. Create a 'Page Backed' instagram account.
This is for when you don't have an existing instagram account you want to link to your page, and want to instead create a 'shadow' instagram account based off your page.
You can generate a paged backed instagram account by performing a POST on the following endpoint. And retrieve an existing one, by performing a GET.
<PageId>/page_backed_instagram_accounts
** Note that both these endpoints require you to have a 'page access token' rather than the normal 'account access token' you use to create your ads.
To get your page access token, you can do a GET request on:
/me/accounts
Then, as stated in the accepted answer - pass your new, linked instagram account id as the instagram_actor_id in your ad creative request.
Sources:
https://developers.facebook.com/docs/marketing-api/guides/instagramads/
https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens

Is it possible to get facebook user's name and main profile picture by url?

Looks like atm it is not allowed to do, because any requests like
https://graph.facebook.com/user_name
return
{
"error": {
"message": "(#803) Cannot query users by their username (user_name)",
"type": "OAuthException",
"code": 803,
"fbtrace_id": "DhZmj6bMhSC"
}
}
And to get user id, i need access_token, which can be retrieved only when user is going through oauth procedure.
So, there are no ways to do that?
There is no way to get any data without authorization, and there is no way to get the username anymore. You can only get the name (first_name, last_name). This call would return the name and the profile picture, with a User Token:
/me?fields=name,first_name,last_name,picture&access_token=xxx
This is mostly for privacy reasons, users who did not authorize your App are none of your business and you would not be allowed to do anything with their data anyway.

Facebook Graph API privacy setting CUSTOM with allow return error - (#100) Only friends may be specified in allow and deny lists

I am trying to do the following in Facebook Graph Explorer using my app's token.
POST /v2.6/me/live_videos?description=hello%20world&privacy={'value':'CUSTOM','allow':'<friend id>'}&title=welcome
But I am getting the following error, am I doing anything wrong? Should the friend id be app-scoped user id instead?
{
"error": {
   "message": "(#100) Only friends may be specified in allow and deny lists",
    "type": "OAuthException",
    "code": 100,
    "fbtrace_id": "BOcQttKPs5W"
  }
}
The problem here is that you need to know so-called "app scoped user id" of the friend you want to add.

Getting Public Info about Location in Facebook Graph API

I need to get the living city of each person in a group. Including people that are not my friends.
In the browser seeing facebook profile of some unknown person, they show "lives in ...", if this is set as public information. They include the link to the city object with the city id in the link. That's all that I need.
But, using a facebook app that I created to use the facebook graph api, this information is not public. I can only get the user propriety 'location' from friends of my that I have permission to see it. I gave ALL the possible permissions to my app.
In the api explorer, when I use it as REST, they show few informations about someone not friend of mine.
https://developers.facebook.com/tools/explorer/
Also in the api explorer, when I use the FQL, it didn't works.
This query works, returning the JSON with the data:
SELECT uid, name FROM user WHERE username='...';
But this other query doesn't work:
SELECT uid, name, location FROM user WHERE username='...';
They return a json with a error code:
{
"error": {
"message": "(#602) location is not a member of the user table.",
"type": "OAuthException",
"code": 602
}
}
I asked for ALL the permissions options in the token. And I can get this info in the browser version of the facebook. But how can I get it with the API ?
The location field only exists in the Graph API table. Since you are using FQL, here are the location fields available to you:
current_address: the current address of the user,
current_location: the user's current location,
hometown_location: the user's hometown (and state).
Permissions:
user_location or friends_location permissions to view: current_location,
user_hometown or friends_hometown permissions to view: hometown_location.
Source: https://developers.facebook.com/docs/reference/fql/user/

Retrieving facebook user wall posts through graph API

I'm currently working on a facebook app which captures wall posts for a specified user, page or group, after a user has authorized the app I quote the access_token that is returned to call the method
https://graph.facebook.com//feed?access_token=
this works fine for pages and groups as we only need a valid token, however for users the results are different depending on the relationship between the user who authorized the app the user whose posts are being captured.
For example if there is no relationship between the two users some posts are not returned even though they are public and displayed when you view the profile of the user, however if they are friends more posts are returned.
Can someone please explain this behaviour? And is it possible to obtain all posts using this method?
Yes, per the permissions listed at https://developers.facebook.com/docs/reference/api/permissions the results of the call are different depending upon the relationship.
However when things are public and you use an access token that doesn't belong to the user, then no results are returned. I cannot remember a time when this wasn't this way. For some odd reason (by design or omission on Facebook's part) using the graph API to get at public posts using a user access token just doesn't want to work.
For example, You can see some public items here
http://www.facebook.com/zuck
http://graph.facebook.com/zuck
However, you cannot seem to get any feed from here without an access token
https://graph.facebook.com/zuck/feed
{
"error": {
"message": "An access token is required to request this resource.",
"type": "OAuthException"
}
}
Let's try adding an user access token that does not belong to zuck or a friend of zuck. https://graph.facebook.com/zuck/feed?access_token={UserAccessToken}
And here's what we get:
{
"data": [
]
}
What about an app access token? Let's try
https://graph.facebook.com/zuck/feed?access_token={AppAccessToken}
{
"error": {
"message": "Invalid OAuth access token signature.",
"type": "OAuthException"
}
}
So as you can see, it's difficult to get things via the graph that are not in alignment with your access token.
I manage to get most of the feeds from user's wall post. Although this is a old post, I hope someone can manage to get what they want from my answer.
Before getting the access token(to get the feeds), you need to add multiple correct Read Permissions "keys".
For example, you will have to add "read_stream", and "user_status" (which I found that these are the most important permission "key" to generate the correct access token, to retrieve one's so-called "public" feeds).
You can add more into generating the access token, in either you want the permission to GET, or POST, or BOTH.
Source is here: https://developers.facebook.com/docs/howtos/ios-6/#nativeauthdialog
One thing that I found is, the way to get the feeds result from user's "Home/About" page and Facebook Page (which is created for people to like (not add friends)) are different. The key is mentioned above, "read_stream", and "user_status". So it's better that you add both of the permissions in order to generate the access token to get everything in feeds.
Graph API doesn't return posts to the App if is not authorized to read user feed, even if posts are public.
Source: https://developers.facebook.com/bugs/290004301178437/
According to the latest api ,
FB.api("/me/feed","get",function(response) {//callback})
should do and also work well .
It is working now but facebook may change it in future.