Get Commenter's Profile Picture - Facebook API - facebook

I have this code
var source = new EventSource("https://streaming-graph.facebook.com/<livestream id>/live_comments?access_token=<access token>&comment_rate=ten_per_second&fields=from{name,id,picture},message,attachment");
source.onmessage = function(event) {
}
But it only includes the profile photo of Pages that comment on the livestream. It doesn't have the profile picture data for Regular Users who comment on the stream.
event data when a Page comments:
from: id: "104156481935516" name: "Person 1" picture: {data: {…}}
[[Prototype]]: Object id: "458166779554976_383292267259200" message:
"test comment""
event data when a Regular User comments:
id: "458166779554976_751936735966533"
message: "regular user test comment"
Is there a way to get the profile picture of the Regular Users? I also can't get their names. I already tried
http://graph.facebook.com/<user id>/?fields=picture&type=large&access_token=<access token>
but I get the error:
{
"error": {
"message": "Unsupported get request. Object with ID '<user id>' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "AfEpta2noSLzSiJ32LdqJAS"
}
}
I only get the error above when trying to fetch other people's profile pic. It works ok when I try to fetch my Page or other Pages.

Related

Can't block a user from a page using Facebook Graph API

According to this page, you can use GET graph.facebook.com/{page-id}/blocked endpoint to see a list of blocked users and pages from one of your pages. You can also use the POST and REMOVE methods along with user parameter to add or remove a user from your Page's block list.
But it seems not to be working. With the GET query and the appropriate Page Access Token, I receive a blank list just like this:
{
"data": [
],
"paging": {
"cursors": {
"before": "MAZDZD",
"after": "MjQZD"
},
"next": "----------"
}
}
If I try to add some user to the block list of one of my pages, I receive this:
{
"error": {
"message": "(#100) The global id ------- is not allowed for this call",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "-------"
}
}
Why I can't see the list of blocked users and pages from my pages? And why can't I block someone: maybe I need the Page Scoped User ID? But how can I get this?
Thanks.

I wanna get posts' usernames through their(posts') ids if I they don't belong to me. So, how can I do it?

I have two access_tokens:
From Instagram Graph API:var fs_access_token, which I get after I log in with Facebook;
From Instagram Basic Display: var inst_access_token;
SO
I have the collection of posts' ids, which I get through ig_hashtag_search:
var posts_ids; //!= null;
I also have 3 posts on my Instagram business account.
And I try to get usernames of all this posts that I have in my collection with one endpoint:
for (var u = 0; u < posts_ids.length; u++) {
fetch("https://graph.instagram.com/" + posts_ids[u] + "?fields=username&access_token=" + inst_access_token).then(function (response) {
response.text().then(function (text) {
alert(text); //using Instagram Basic Display
});
});
}
But then I get the error from this request:
{
"error": {
"message": "Unsupported get request. Object with ID '17884048231750634' does not exist, cannot be loaded due to missing permissions, or does not support this operation",
"type": "IGApiException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "AKiycowo9LbwZbKzxOL-EQ9"
}
}
Interesting fact: if I insert the id of one of posts that I have on my Instagram business account instead of posts_ids[u], then it WILL work!
SO, what the hell's going on here? It means that I can get "username data" only from posts that I have on Instagram account, doesn't it? Or what?
I also tried to get usernames with other endpoind, where of course I used other access_token, which I get after I log in Facebook(access_token that I used above was access_token, which I get after I log in Instagram; Instagram Graph API - log in Facebook, and Instagram Basic Display - log in Instagram):
for (var u = 0; u < posts_ids.length; u++) {
fetch("https://graph.facebook.com/v8.0/" + posts_ids[u] + "?fields=username&access_token=" + fs_access_token).then(function (response) {
response.text().then(function (text) {
alert(text);
});
});
}
But then I again get the error from request:
{
"error": {
"message": "Unsupported get request. Object with ID '17884048231750634' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "AhN5o9eopccP4NrQsu8QuaN"
}
}
And again interesting fact: if I insert the id of one of posts that I have on my Instagram business account instead of posts_ids[u], then it WILL work!
I also tried to do so:
for (var u = 0; u < posts_ids.length; u++) {
fetch("https://graph.facebook.com/v8.0/" + posts_ids[u] + "?fields=username&access_token=" + inst_access_token).then(function (response) {
response.text().then(function (text) {
alert(text);
});
});
}
and
for (var u = 0; u < posts_ids.length; u++) {
fetch("https://graph.instagram.com/" + posts_ids[u] + "?fields=username&access_token=" + fs_access_token).then(function (response) {
response.text().then(function (text) {
alert(text);
});
});
}
But then I get this error:
{
"error": {
"message": "Invalid OAuth access token.",
"type": "OAuthException",
"code": 190,
"fbtrace_id": "ARVMttFmcIAfwBTPdYcMEfQ"
}
}
Most likely, this is because I am trying to combine the access token from Instagram with the technology for working with Facebook and the access token received from Facebook with the technology for working with Instagram.
So couldn't you please help me to find endpoint in Instagram Basic or Instagram Graph which allows to get usernames from posts of the OTHER users(especially through ids which I get with Hashtag Search/recent_media)? Or couldn't you help me to understand how to use it correctly? Because I am a beginner and may not know some details. Please, help me!
Unfortunately you can't. You can find the following under the Limitations section on the hashtag endpoints.
You cannot request the username field on returned media objects.
Ref: https://developers.facebook.com/docs/instagram-api/reference/hashtag/recent-media

How to get instagram username from new facebook graph API

Looking at the new Instagram Graph API - there is no direct way to retrieve username once a user is logged in. Although it says in the official document that a call like
"https://graph.facebook.com/v3.2/17841405822304914?fields=biography%2Cid%2Cusername%2Cwebsite&access_token=EAACwX..."
should return the following:
{
"biography": "Dino data crunching app",
"id": "17841405822304914",
"username": "metricsaurus",
"website": "http://www.metricsaurus.com/"
}
This currently returns an error, and looks like there is no such option to get only username of an instagram business user.
If you are talking about fetching username of an instagram business account which is linked to your facebook page, you can use the below curl
curl -i -X GET "https://graph.facebook.com/v3.2/me/accounts?fields=instagram_business_account%7Busername%2Cname%2Cig_id%7D&access_token=<access_token>"
Please replace access_token with your user access token in the above curl.
Sample reponse which you will get for the above curl is as below :
{
"data": [
{
"instagram_business_account": {
"username": "<instagram user name>",
"name": "<instagram display name>",
"id": "<corresponding facebook graph id for instagram profile>",
"ig_id": <instagram profile id>
},
"id": "<facebook page id>"
}
],
"paging": {
"cursors": {
"before": "MTc2Njg1MTU2MTI1ODA1",
"after": "OTg3MzU1NzExNDUwMDg3"
}
}
}
If it helps to someone.. Now its better to do it like this GrapAPI v10.0
FB.api('/' + pageID + '?fields=instagram_business_account{id,name,username}',
function (response) {
// TODO: whatever you want
},
{ access_token: accessToken }
);
EDIT: I wouldn't do it this way anymore. Its very old code, I would wrap it somehow and I am not sure this still works..
I was able to solve this only by using the old api.
According to their documentation, although the old API is about to become deprecated, as of now, it is meant for small businesses or personal apps.
The new Instagram Graph API is "An API for accessing data in large- and medium-sized Instagram Business Accounts"
Looks like FB doensn't know it's way around.

Get user id and name from comment on Fan Page Wall

Since Facebook API update to v2.11, I cannot get User Id and Name from comments on FanPage Wall Post. Anyone can help/explain?
Usually I used this :
https://graph.facebook.com/[POST_ID_PAGE]/comments?order=reverse_chronological&access_token=[YOUR_ACCESS_TOKEN]
And the result just like :
{
"data": [
{
"created_time": values_date_TMZ,
"from": {
"name": USER_NAME,
"id": USER_ID
},
"message": THE_COMMENT,
"id": THE_COMMENT_ID
}
}
You need a Page Token now, to get user names - check out the changelog:
https://developers.facebook.com/docs/graph-api/changelog/version2.11#gapi
I assume you are using an App Token at the moment.
Edit: Of course it has to be a Page Token of the Page with the comment. And of course you need to manage the Page - else you would not even get a Page Token.

Getting attachments from Facebook conversations

I currently use the Facebook Graph API to get a inbox conversation. Most of the messages look like this:
{
"id": "1452301718360191_1407164668",
"from": {
"id": "10203840837848742",
"name": "Øyvind Knobloch-Bråthen"
},
"message": "Some message",
"created_time": "2014-08-04T15:04:28+0000"
}
However, some of the messages in the conversation are images, and they are represented like this:
{
"id": "1452301718360191_1407164668",
"from": {
"id": "10203840837848742",
"name": "Øyvind Knobloch-Bråthen"
},
"created_time": "2014-08-04T15:04:28+0000"
}
So basically what is different is that the message is gone. But since there is no mention of the attachment, or url to the image or anything else I can use, I'm not able to display the image in my app.
So my question is: How can I get a hold of the image (or url to the image). Hopefully it will be available in some way when I have the message ID.
With Graph api V2 the egde to retrieve inbox messages is /id/conversations
id is eitheir a user id or a page id
Each conversation message with attachment should return an "attachments" field.
Then for each message with attachment you should query the url https://api.facebook.com/method/messaging.getattachment?mid=message_id&access_tokes=your_access_token
Note that it does not work with graph api v2.1. Unless you curl the query