Facebook object API - duplicate objects created - facebook

I am creating objects through the open graph object API, and attaching these to published stories. Both the object and the story are created, and FB returns id's as if everything worked out just fine.
However, while submitting the object/story for review it turned out two objects are created (of different object types) even though I only make one HTTP POST request.
Background
Our app is using namespace 'mynamespace'
We have created a custom open graph object with name 'myobject'
We have created a custom open graph action with name 'myaction'
Request details:
1) First we create an object:
POST /me/objects/mynamespace:myobject HTTP/1.1\r\nConnection: close\r\nHost: graph.facebook.com\r\nContent-Length: LENGTH\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n
URI decoded http body:
access_token=TOKEN&object={"url":"http://url.com","title":"My title","image":"https://imageurl.com","description":"My description"}
Response:
"{\"id\":\"123456789\"}"
2) Then we create a story (with this object referenced):
POST /me/mynamespace:myaction HTTP/1.1\r\nConnection: close\r\nHost: graph.facebook.com\r\nContent-Length: LENGHT\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n
URI decoded http body:
access_token=TOKEN&myobject=123456789&fb:explicitly_shared=true&message=User generated message
Response:
"{\"id\":\"12121212121\"}"
Expected result
One object of type mynamespace:myobject should be created
One story of type mynamespace:myaction should be created
Actual result
One object of type mynamespace:myobject is created
One story of type mynamespace:myaction is created
One object of type Object is created (according to reviewer)
One action of type Post is created (according to reviewer)
Only one story turned up in the user feed and in the object browser, but the reviewer told us following:
Your action produces more than one published story when the user triggers the action. Users shouldn’t be surprised by multiple stories being published for a single in-app action. The action I took produced a "post" and a "myaction" story.
We had a look under (Open Graph -> Types) and it turned out that each time we make this request an object of type 'Object' and an action of type 'Post' is automatically created/defined! This must be what the reviewer complains about, but we haven't been able to figure out what we're doing wrong!
Any suggestions on how this can be solved is be very much appreciated.
Exact same issue when using the Open Graph API explorer
Turns out the exact same thing happens when creating an object through the Facebook Graph API explorer. When doing so the 'Object' object and the 'Post' action suddenly appears under Open Graph -> Types. Right now I see following reasons to this issue:
The object/action/story is set up incorrect in some way
The reviewer thought it was an issue when it actually wasn't
It's a FB bug
Object(s) created through the Graph API explorer
When creating an object through the Graph API explorer this is the resulting object:
{
"id": "4324324234234234",
"url": "http://url.com",
"type": "mynamespace:myaction",
"title": "My title",
"image": [
{
"url": "https://imageurl.com"
}
],
"description": "My description",
"updated_time": "2013-07-09T14:14:38+0000",
"created_time": "2013-07-09T14:14:38+0000",
"application": {
"id": "432423423423",
"name": "appname",
"url": "https://www.facebook.com/apps/appurl"
},
"is_scraped": false,
"post_action_id": "23423423423423423"
}
The 'post_action_id' seems weird, and when requesting that object I get:
{
"id": "423423423423",
"from": {
"name": "My name",
"id": "234234"
},
"start_time": "2013-07-09T14:14:38+0000",
"end_time": "2013-07-09T14:14:38+0000",
"publish_time": "2013-07-09T14:14:38+0000",
"application": {
"name": "appname",
"namespace": "mynamespace",
"id": "432423423423"
},
"data": {
"object": {
"id": "4324324234234234",
"url": "http://url.com",
"type": "mynamespace:myaction",
"title": "My title"
}
},
"type": "og.posts",
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
}
The fact that the object already has a related og.posts object must be what the review think is the issue here. I still don't understand why this og.posts object automatically shows up as an open graph object though.

The issue here is that when the user clicks the "Peace" button on your site, two Open Graph actions are published and that's against our policy - one user action should not publish multiple stories. If you log in as your Open Graph Test User and check the Activity Log, you'll see the following two published actions with the same timestamp:
https://www.facebook.com/100006264788511/activity/1388570951361718
https://www.facebook.com/100006264788511/activity/1388570924695054
Are you sure your code is only making a single call to the Graph API when publishing the action?

I'm not sure how this would map to your POSTs, but I was dealing with the same issue on iOS and the problem is posting both the object and the action. If you set the object on the field other of the action (instead of the objectId after posting) only one Activity is created.
In my case, instead of doing:
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
object.provisionedForPost = YES;
object[#"title"] = #"Title";
object[#"type"] = #"video.other";
object[#"url"] = url;
[FBRequestConnection startForPostOpenGraphObject:object
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error && [result objectForKey:#"id"]) {
NSString* objectId = [result objectForKey:#"id"];
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
action[#"explicitly_shared"] = #"true";
action[#"other"] = objectId;
[FBRequestConnection startForPostWithGraphPath:#"me/myNamespace:post"
graphObject:action
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
// handle success and failures
}];
}
}];
I had to do:
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
object.provisionedForPost = YES;
object[#"title"] = #"Title";
object[#"type"] = #"video.other";
object[#"url"] = url;
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
action[#"explicitly_shared"] = #"true";
action[#"other"] = object;
[FBRequestConnection startForPostWithGraphPath:#"me/myNamespace:post"
graphObject:action
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
// handle success and failures
}];

Related

Get Commenter's Profile Picture - Facebook API

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.

MS Graph REST API checkout user

I've managed to successfully checkout a file using the https://graph.microsoft.com/beta/drives/{driveId}/items/{itemId}/checkout
Now, I'd like to get the information about the user, who actually perform the checkout operation.
It's possible to check if the item is locked:
https://graph.microsoft.com/beta/drives/{driveId}/items/{itemId}?select=*,publication
However, according to DOCs, publication doesn't provide information about the checked user. Without information who locked the file is the whole checkin/checkout logic is useless.
This kind of information could be retrieved via the metadata for an item in a list as demonstrated below:
https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items/{item-id}?expand=fields(select=CheckoutUserLookupId)
Once you get checkout user id (CheckoutUserLookupId field) , user details could be determined via the following endpoint:
https://graph.microsoft.com/v1.0/sites/{site-id}/lists('User Information List')/items/{CheckoutUserLookupId}
where CheckoutUserLookupId is the user id from the previous request
https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items/{item-id} can't work with folders.
Anyway, drive endpoint "Allows access to the list as a drive" (according to MS Graph Docs). It works with folders as expected.
So I have
get the drive-id: /sites/${siteId}/drives
list root folder: /drives/{drive-id}/items/root/children?select=name,publication
if an item is locked, it's possible to list the activity on the item:
/drives/${idObj.driveId}/items/${idObj.fileId}?select=id&expand=activities
return list of actions:
"activities": [
{
"#odata.type": "#oneDrive.activityEntity",
"#odata.id": "https://xxxxxxxxxx/v2.0/oneDrive.activityEntity2a3649d6-2xxxxx",
"#odata.editLink": "oneDrive.activityEntity2a3649d6xxxxxx",
"#sharePoint.localizedRelativeTime": "0|July 30",
"action": {
"checkout": {}
},
"actor": {
"user": {
"email": "XXX#XXX",
"displayName": "vladimir",
"self": {},
"userPrincipalName": "XXX#XXX
}
},
"id": "XXXXXXXXXXXXXX",
"times": {
"recordedTime": "2018-07-31T04:59:03Z"
}
},
although no user ID at least a have the email....

How to fetch comments with Facebook Graph API from comments plugin

I am trying to get all comments from my website.
I have found this method in plugin FAQ:
https://graph.facebook.com/v2.6/?fields=og_object{comments}
&id=<YOUR_URL>
&access_token=<YOUR_TOKEN>
But it neither corresponds to API reference (there's no field named comments in returned OpenGraph object), nor actually works. So I managed only to fetch amount of comments, but not actually their contents. Is it possible to do so?
The code referred to in the FAQ appears to be for v2.6 of the API, and so may be superceded.
I get comments from the Comments Plugin with the following.
First I get the Facebook Graph ID for the URL the Comments Plugin is operating within:
https://graph.facebook.com/v2.8/?id=<<YOUR_URL>>
&access_token=<<YOUR_TOKEN>>
This returns a response like this:
{
"og_object": {
"id": "<<OBJECT_ID>>",
"description": "<<OPENGRAPH_DESCRIPTION>>",
"title": "<<OPENGRAPH_TITLE>>",
"type": "article",
"updated_time": "2017-02-08T13:53:48+0000"
},
"share": {
"comment_count": 0,
"share_count": 0
},
"id": "<<YOUR_URL>>"
}
We then take that Open Graph Object ID and plug it into this:
https://graph.facebook.com/v2.8/<<OBJECT_ID>>/comments?summary=1
&filter=stream
&order=reverse_chronological
&access_token=<<YOUR_TOKEN>>
You'll get an object with a data property which will be an array of comments.
Testing for URL Provided by OP
https://graph.facebook.com/v2.8/
id=http://pdffiller.com/6962253&access_token=[REDACTED]
Returned
{
"og_object": {
"id": "1195506680497732",
"description": "Fill w9 fill out online 2014-2017 form irs instantly, download blank or editable online. Sign, fax and printable from PC, iPad, tablet or mobile. No software. Try Now!",
"title": "2014-2017 Form IRS W-9 Fill Online, Printable, Fillable, Blank - PDFfiller",
"type": "website",
"updated_time": "2017-02-08T12:08:37+0000"
},
"share": {
"comment_count": 0,
"share_count": 24
},
"id": "http://pdffiller.com/6962253"
}
Note the comment_count is zero, hence why no comments are returned by the Graph API

How should we retrieve an individual post now that /[post-id] is deprecated in v2.4?

I just tried through the Graph API Explorer with this path /v2.4/10153513872748291 and I've got this result:
{
"error": {
"message": "(#12) singular links API is deprecated for versions v2.4 and higher",
"type": "OAuthException",
"code": 12
}
}
But https://developers.facebook.com/docs/reference/api/post/ doesn't say anything about deprecation.
I'm not sure if I miss something, or there's another way to get info about an individual post.
Edit: v2.3 works, but v2.4 is the latest one.
Looks like you now need to the combination of the id of the user or page that made the post (or whose wall it is on), an underscore, and then the post id.
For your example post, 10153513872748291, that is made by a page Drama-addict, that has the id 141108613290 – so 141108613290_10153513872748291 will work.
And so does 788239567865981_10153513872748291, because 788239567865981 is the id of the user making the post.
Firstput userId underscore add postId /Likes to check Like status in facebook
userId_post_Id/Likes to fetch Likes Records
userId_post_Id/Comments to fetch Comments Records
https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=303261006522998_751199848395776%2FLikes&version=v2.9
**In this link Right side Get Token indide GetAccessToken to select Permission**
303261006522998_751199848395776/Likes
303261006522998_751199848395776/Comments
{
"data": [
{
"id": "124778301449917",
"name": "Manisha Gera"
},
{
"id": "1680577265523548",
"name": "Rubi Sharma"
}
],
"paging": {
"cursors": {
"before": "MTI0Nzc4MzAxNDQ5OTE3",
"after": "MTY4MDU3NzI2NTUyMzU0OAZDZD"
}
}
}

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