Facebook graph api like an external url, statistics - facebook

I am using a Facebook graph api to like an external url:
Method: POST
URL:
https://graph.facebook.com/v2.1/{userId}/og.likes
Header:
application/x-www-form-urlencoded
Body:
access_token={appId}|{appSecrect}&object={"url":"{myUrl}", "title":"{myTitle}"}
It is publishing successfully, returning an Action Id.
I have 2 problems:
I can keep liking with the same user Id and it will always succeed.
I can find my url in object_url table, but link_stat and url_like do not contain any information about this url.
Another strange thing, is if I publish my url like this:
access_token={appId}|{appSecrect}&object={myUrl}
The first request throws an error "title is missing".
The second time the same request returns success.
After that for the same requests it is able to distinguish that a user already liked the url. And I have information in link_stat table.

I finally found the solution.
1. Create an object
This request creates an object "link" and returns an Object Id.
URL: /app/objects/website
Header: Content-Type: application/x-www-form-urlencoded
Body: UrlEncode object's json!
access_token={appId}|{appSecret}&object={
"title":"Happy event",
"image":"{img_url}",
"url":"{custom_url}",
"description":"{description}",
"data": {} }
You can read more here:
https://developers.facebook.com/docs/opengraph/using-objects
2. Like an object
This request will "like" your link on behalf of the user.
It will show in the user's timeline as "User likes a link on you Application site..".
Make sure:
1. User has granted "publish_actions" permission;
2. Your application is apprved for submission of the likes. Otherwise only administrators, developers and testers of you Application can make "likes".
For more information read this :
https://developers.facebook.com/docs/opengraph/submission-process
URL: /v2.1/{user_id}/og.likes
Header: Content-Type:application/x-www-form-urlencoded
Body: object={object_id}&access_token={appId}|{appSecret}
3. Get likes for an object
URL: /v2.1/{object_id}/likes?access_token={appId}|{appSecret}

Related

How to get Instagram post URL from Facebook Graph media_id

I'm using Instagram Mentions API and was able to obtain FB media_id for couple Instagram posts.
I need media_id to get post content via /user/mentioned_media. Unfortunately that endpoint does not provide ig_id or shortcode or permalink which I need.
Is there a way to get Instagram Post URL with FB Graph API media_id?
It seems like you can get media metadata (and all comments/replies) when someone #-mentions you in a non-owned-media comment by using a query like below.
You would use your own instagram business account id for the first number (the path component), and you'd use the comment_id you received from the webhook comment-mention notification as the second number:
/12345678901234567890?fields=mentioned_comment.comment_id(9876543210987654321){id,text,username,timestamp,media{id,media_type,media_url,permalink,username,like_count,comments_count,comments{id,text,username,user{id,username},like_count,timestamp,replies{id,text,username,user{id,username},like_count,timestamp}}}}
Yes, there is a way you can get Instagram post URL associated with a media if you know the media id.
You can also get more information (all its fields and edges) on media. See the docs here
You can get the Instagram post URL by making a GET request to /{ig-media-id}
Sample Request:
GET https://graph.facebook.com/v15.0/{{media_id}}?fields=permalink, shortcode&access_token={{ACCESS_TOKEN}}
Sample Response:
{
"permalink": "https://www.instagram.com/p/Clxsi5Pol2_/",
"shortcode": "Clxsi5Pol2_",
"id": "17xxx59557977xxx"
}
The value of the permalink is the valid public URL for the post.
You can also use the shortcode returned to construct the URL by concatenating the shortcode to https://www.instagram.com/p/.

Facebook Graph API URL Scrape Inconsistent

I am running queries against Facebook Graph API to fetch OG meta information about URLs. Using a Facebook APP token, I can request most URLs and get their corresponding meta data back. But I have run into two issues that I can't find a solution for. I have one domain that refuses to pull any meta information using an APP token. Instead I get back an error 100 (Unsupported post request). But when I make the same request using a User Access Token, it works correctly. The second issue I found is that when a URL has any kind of OG error, Facebook is still scraping it, but will return a 100 error instead of returning the meta details (with both the app token and the user access token). I've even tried running the query without the scrape parameter, to no avail.
Normal Request That Returns Meta Fields of URL:
POST:
https://graph.facebook.com/v2.9/
{
"id": "http://viralcrunch.com/articles/22325/these-guys-invented-the-anti-smart-phone-and-it-will-blow-your-mind",
"scrape": "true"
}
Request That Returns 100 Unsupported post request Error W/ App Token
POST:
https://graph.facebook.com/v2.9/
{
"id": "http://turnthispage.com/dads-totally-winning-fatherhood/",
"scrape": "true"
}
Request That Returns 100 Invalid Object Error W/ Any Token
POST:
https://graph.facebook.com/v2.9/
{
"id": "http://www.thesportster.com/basketball/top-20-nba-players-who-live-life-to-the-fullest/",
"scrape": "true"
}
The second URL seems to be associated with an app id of an app that has some kind of access restrictions set; so I guess it is the same here as if you tried to access information about a Facebook Page that has access restrictions set - you can not query any details about those using the app access token, you need to use a user access token for a user that is allowed to see the content, or a page access token for that page.
And that you get an error response for the third one seems only natural. After all, this is a tool intended to debug and scrape the Open Graph objects you are in control of, so if the OG meta data is not in order it should return an error.

Why do some Facebook urls not return their Facebook page id through graph api?

For most Facebook urls, a call to the graph api with a query string parameter of ids set to the url, returns the Facebook page of that url correctly....
https://graph.facebook.com/?ids=http://www.facebook.com/AdvantageInsulationNY&appToken&access_token=XXXXXXX
returns
{
https://www.facebook.com/AdvantageInsulationNY: {
id: "XXXXXX",
about: "about"
......
}
}
However, some simply return the url as the value of the id element...
https://graph.facebook.com/?ids=http://www.facebook.com/winetreefarm&access_token=XXXXXXXX
returns
{
https://www.facebook.com/winetreefarm: {
id: "https://www.facebook.com/winetreefarm"
}
}
I can't find an explanation of why this page does not return its page id or how to obtain the id (knowing the url) through the graph api.
I can get the id utilizing FQL, but only when sending the url as http (not https) and I want to use the graph api.
There is another question similar to this here: Facebook Graph API - get ID for a URL?
But none of these answers fit my situation (there is a like button on the page).
Any ideas?
Thanks,
Matt
I figured it out. This has to do with page restrictions and the token you are using. Because the page is marked as alcohol content its not viewable to anyone, so just my app token isn't good enough. If I access it with the user token, then I get the full information.

How can I get user's facebook interests?

I am trying to get interest from Facebook Api but empty array is returned.
I have searched for other issues like:
How to get user Interests? (//stackoverflow.com/questions/12422714/how-to-get-user-interests)
How can I get the interests of my friend through facebook api?(//stackoverflow.com/questions/6587373/how-can-i-get-the-interests-of-my-friend-through-facebook-api)
In "Graph API Reference" (developers.facebook.com/docs/graph-api/reference/v2.1) is defined a full list of nodes. If I click in 'user' and click in 'interest' I am redirected to "/{user-id}/interests" (//developers.facebook.com/docs/graph-api/reference/v2.1/user/interests) description. In this description are defined serveral points:
Endpoint: GET /user/interests
Permission: user_interests
Descrption: The interests listed on someone's profile under "Likes > Interests" (//www.facebook.com/me/likes_interests).
I am using Graph API Explorer for to test. I have used all api versions (from unversioned to v2.1).
If I get a valid access token with aproppiated permission and I do a request to endpoint "/me" I have a successfully response with data.
If I do a request to endpoint "/me/interests" I have a empty response:
{
"data": [
]
}
My user in Facebook is following a list of interest for example: stackoverflow group.
If I do a request to movies or books the response are empty too. But if I do a "like action" in a book or movie and try again I have a successfull response. If I try again with "/me/interest" response is empty yet.
I believe that I do not understand concept of "interest" or something is wrong and I can not see it.
Which is the way for to recovery the interests of an user?
The interests are specified in the Profile section, and not via Like actions! The list you linked is not an interest either.
Books and Movies can be requested with the user_likes permission, so if you didn't request that the response will be empty as well.

Bad Request/Method not Implemented Error when Publishing Actions to the Timeline

I am working on a Joomla site and using myApi to handle most facebook integrations. The like button is working fine and picking up information from the og meta tags inserted by myApi.
On the website, the user can login using facebook - I have added the publish_actions permission to the myApi code, and I know this is being requested because when authorising the app, the oauth dialog says that actions like ordering from restaurants (the action i added to my fb app) will be posted to the timeline.
now, while ordering, I check whether the user has an entry in the myApi user table and if so, I provide a checkbox that lets the customer choose whether she wants the order action posted to her timeline. if ticked, I then use curl to try and post the order action to facebook. I have been using my account to test - I have authorised the app with all permissions requested. I use the myApi interface to get my user access token. I am adding the access_token and object url to the url as querystring parameters and then posting to it through curl.
The curl response I get is:
<HTML><HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>Method Not Implemented</H1>
Invalid method in request<P>
</BODY></HTML>
the response I get when going to the generated url in my browser is
{
"data": [
],
"paging":{
"next": "https://graph.facebook.com/me/og_collegekhana:order_from?restaurant=http\u00253A\u00252F\u00252Fwww.collegekhana.com\u00252Fstates\u00252Ftamil-nadu\u00252Fcampus-1\u00252Feat-1&access_token=[the token I got]&offset=25&limit=25"
}
}
I checked the object id of the url using
https://graph.facebook.com/?ids=http://www.collegekhana.com/states/tamil-nadu/campus-1/eat-1
I am not getting an object id. instead I get
{
"http://www.collegekhana.com/states/tamil-nadu/campus-1/eat-1": {
"id": "http://www.collegekhana.com/states/tamil-nadu/campus-1/eat-1"
}
}
I am completely lost and hope someone can tell me what I am doing wrong.
The problem was that instead of doing a cURL POST, one has to add the querystring parameter
method=post to the URL.