I need to get the id of the URL posted to the wall, but the documentation says I can get the id from the the url I posted, but that id isn't usable because the id IS a url? Here is the code.
Just post to the Graph API:
curl -XPOST -F"id=https://your-url.com" \
-F"scrape=true" https://graph.facebook.com
It should return some JSON including the ID of the url:
{
"url":"https:\/\/your-url.com\/",
"type":"website",
"title":"https:\/\/your-url.com\/",
"updated_time":"2011-11-14T07:05:22+0000",
"id":"10150375340063123"
}
Related
When blocking a user from a page via Facebook API getting valid response but can not understand what it means.
Request to block a user:
curl -i -X POST \
"https://graph.facebook.com/v14.0/1111666294606851/blocked?asid=%5B104062075441111%5D&access_token=totoken"
returns:
{
"104062075441111": false
}
For other users it returns true
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/.
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.
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}
I can successfully create right column ads, but failed to create NewsFeed ads.
According to what I know, I should create type 27 creative first, and for this purpose, I need to provide parameter object_id and story_id. The first one is our company's facebook page, and the 2nd one is an unpublished post on that page.
To create a story, I used the codes below. I think it should be 'promotable_posts'. This is to create an unpublished post in the page so that it can be used in the newsfeed ad.
$api.put_connections('id_of_companys_fb_page', 'promotable_posts',
{
"message" => 'my_message',
"name" => "my_name",
"link" => "url_of_a_page",
"caption" => "my_caption",
"description" => "This is a longer description",
"picture" => "url_to_a_picture"
}
Unfortunately it always throws exception "type: GraphMethodException, code: 100, message: Unsupported post request. [HTTP 400] (Koala::Facebook::ClientError)".
If I change 'promotable_posts' to 'feed', then it works, but I cannot use the post id to create the ad, and I noticed that the id starts with 5xxx.. which is different from other manually created posts ids (starting with 1xx..) that worked. I even tried other types, but none works. I didn't find an example to create such post.
Any suggestions, even wild-guess, are appreciated.
Are you using the Ads API documentation?
Once you create the page post (via the /feed connection of the page) or have someone create it using the page management interface you create a type 25 or 27 ad using the post ID you retrieve from the API, or from the response of the API call you used to create the post itself.
The /promotable_posts endpoint returns the ID of any posts that can be turned into ads, it's a subset of the posts on /posts
A sample type 25 and 27 ad creative are included in the 'examples' section of the Creative Specs documentation
e.g. the type 27 example, modified to use a specific post ID, not the most recent post on the page:
curl \
-F "name=sample creative" \
-F "type=27" \
-F "object_id=<PAGE ID>" \
-F "story_id= <POST ID>" \
-F "access_token=_____" \
"https://graph.facebook.com/act_<ACCOUNT ID>/adcreatives"