facebook graph API company page URL? - facebook-graph-api

I am working on some data analysis regarding beverage manufacturers in the US and would like to grab posts from the company facebook pages to mine some data using the standard facebook graph API. I am new to the facebook API and I am hoping to get some clarifications here that I can't find in the developer docs.
For a simple example lets look at 2 companies FB pages:
https://www.facebook.com/CocaColaUnitedStates
https://www.facebook.com/BellsBreweryInc
Now per the API documentation, I should be able to retrieve the posts on those public company pages via a URL as follows:
https://graph.facebook.com/COMPANYFBNAMEHERE/feed?access_token=MYTOKEN
or
https://graph.facebook.com/v2.5/COMPANYFBNAMEHERE/feed?access_token=MYTOKEN
This works for CocaCola: https://graph.facebook.com/v2.5/CocaColaUnitedStates/feed?access_token=MYTOKEN
This returns data as I would expect:
{
"data": [
{
"message": "The French \"yes! yes! yes!\" sounds like \"we! we! we!\" (lettered \"oui.\") \"C'est la vie\" sounds like (homonym) \"say LOVIE\" (like lovie dovie).\n\nSong of (rather than \"by\") Robbie Nevil: C'est La Vie\nhttp://www.youtube.com/watch?v=CGtf9QfITQw",
"created_time": "2016-02-06T02:52:17+0000",
"id": "820882001277849_452698638250376"
},
etc....
However when I try this for Bell's: https://graph.facebook.com/v2.5/BellsBreweryInc/feed?access_token=MYTOKEN
I get this:
{
"error": {
"message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"fbtrace_id": "AWTxWye6vub"
}
}
I am not understanding why I am getting an error on Bell's page? It's a publicly available company FB page, so I can't imagine it's a restriction, but I can't understand why it wouldn't be returning the posts like CocaCola?

It sounds like the owner of the token you are using is below the legal drinking age. BellsBreweryInc is a page in the alcohol category so no data will be returned for users under the legal age. This is something BellsBreweryInc would have set in their page settings.

Age restircted websites require a user access token from a user account that meets the page requirements. I was using an app access token which is why it didn't work.
I needed to log into my account and generate a user access token and use that token in the URL.
Also, just realized that token expires in a couple hours. Anyone wanting to do this may also want to read this: How to extend facebook access token in python

Related

Why Graph API Explorer doesn't return the wall 'feed' based on a user's id

When I test the Graph API Explorer from facebook site and write the following parameters:
https://graph.facebook.com/'userid'/feed?access_token='my access token'
it returns
{ "data": [ ] }
I tried it with several group ids and all return the same result.
scope is below
user_birthday, user_religion_politics, user_relationships, user_relationship_details, user_hometown, user_location, user_likes, user_education_history, user_work_history, user_website, user_managed_groups, user_events, user_photos, user_videos, user_friends, user_about_me, user_status, user_games_activity, user_tagged_places, user_posts, read_page_mailboxes, rsvp_event, email, ads_management, ads_read, read_insights, manage_pages, publish_pages, pages_show_list, pages_manage_cta, pages_manage_leads, publish_actions, read_audience_network_insights, read_custom_friendlists, user_actions.video, user_actions.books, user_actions.music, user_actions.news, user_actions.fitness, public_profile
when I tried it from facebook graph api explorer I found out that its not returning any results. Please I would really appreciate the your help
Can you tell me that you are accessing others id by the same token or you are taking a different token??
Because if you are using graph explorer then it will give the token for your ID only. And you can see all the feed of your page using
me/feed?fields=id,posts,from or
your_id/feed?fields=id,posts,from
Use GET request while using submit button.

How to scrape user's facebook feed using Graph API?

I'd like to scrape some user's posts from Facebook. Posts are visible in browser, when I'm logged in and I am looking at http://fb.com/username URL. But when I'm trying to access the same feed using Graph API Explorer (https://graph.facebook.com/v2.3/username/feed) I'm getting:
"error": {
"message": "(#803) Cannot query users by their username (username)",
"type": "OAuthException",
"code": 803
}
If I try to use id instead of username (http://graph.facebook.com/v2.3/userid/feed) I'm getting empty JSON in response:
{
"data": [
]
}
So, is there a way to get the user's feed using Graph API? Or do I have to imitate a web browser and parse HTML then?
You are not supposed to grab the feed of any user, public or not. You need to authorize a user with user_posts to get access to his feed - and his feed only.
Also, usernames are not available in the Graph API anymore, you need to use an App Scoped ID now. You get that when you authorize the user.
Btw, scraping is not allowed at all: https://www.facebook.com/apps/site_scraping_tos_terms.php

Facebook API: Error "(#210) Subject must be a page" when posting a Status Update on a Page

I want to post a simple status update on one of my pages with a perl-script. To find out how to do best, I use facebooks Graph API Explorer https://developers.facebook.com/tools/explorer for experiments
I use the access token of my FB-app. This app is doing a good job since 2 years. The access token will expire in about 2 month and among many other permissions it has the permissions "publish_stream" and "manage_pages".
I select "POST", then, in the field next to "POST", I enter the ID of my page (a 15-digit-number starting with 102 ending with 937). This ID is correct, because I can GET data from this page using exactly this ID.
I click on "Add a field", then I enter the field-name "message" and the value "test-message". Then I click on "Submit". And then I get this result:
{
"error": {
"message": "(#210) Subject must be a page.",
"type": "OAuthException",
"code": 210
}
}
But posting a comment to an existing posting on the same page works fine. I simply replace the page-ID 102...937 with 501...852/comments where "102...937" and "501...852" are 15-digit-numbers.
What am I doing wrong? What must I do to post a message on my page using the Graph API Explorer? "102...937" is the ID of an existing page. I am managing 3 pages, I have the same problem with all 3 IDs.
I found the solution:
In the field next to POST I only did enter the Page-ID (like 123456789012345) but you must add "/feed" to the end, like this: 123456789012345/feed
The documentation does not say how to post a status message. To me it was clear, If want to post something on a page, I have to enter the pages ID, not more. And if the error-message would have said "Subject must be a FEED" everything would have been clear. But is said "must be a PAGE" but it already was a page.

"privacy" is not accepted, when posting to a Page's wall with a Pagetoken

Goal:
I want to specify privacy for posts, that are done through my application, when I post to a Page's wall, using Pagetoken.
Problem:
Using page token, I do post to URL "https://graph.facebook.com/me/feed"
with the following body —
{
"message": "from app with security after requesting a username",
"privacy": {
"description": "Amsterdam, Netherlands, Netherlands",
"value": "CUSTOM"
}
}
An receive such a terrible answer —
{
"error": {
"message": "(#100) Posts where the actor is a page cannot also include privacy.",
"type": "OAuthException"
}
}
Even through it is said in documentation, here - https://developers.facebook.com/docs/reference/api/page/#posts,
that Pages#post.privacy is supported.
And explicitly:
"The description field may contain a comma-separated lists of valid country, city and language if a Page's post targeting by location/language is specified."
Please help me out, what am I doing wrong?
I posted the bug in Facebook Developers Bug reporter tool
https://developers.facebook.com/bugs/238365492903384
Subscribe/Comment to push this for a reply
This looks like a documentation bug. I have attached a screenshot of the old version of the docs. Try using "targeting" with the same location format as:
https://developers.facebook.com/docs/adsapi/targeting_specs/
I've also requested a fix for the docs.

Facebook Graph API - get ID for a URL?

This seems like a pretty obvious, basic thing to expect from the Graph API, but I'm having serious difficulty with it. All I want to do is get the ID for any particular URL. They have a method for this:
https://graph.facebook.com/?ids=http://www.imdb.com/title/tt0117500/
And that works great. But if I try another URL, say for my blog,
https://graph.facebook.com/?ids=http://dusda.vox.com
it doesn't give me back a numerical ID like all of the examples do. Instead, this:
{"http:\/\/dusda.vox.com":{"id":"http:\/\/dusda.vox.com"}}
If I try to use that "id", I get jack (probably because the query string looks impossible to parse):
Request: https://graph.facebook.com/http://dusda.vox.com/likes
Response: {"id":"http:\/\/dusda.vox.com\/likes"}
So what's up with this? Is the Graph API just selectively reliable, or am I misunderstanding something? I've tried it on URLs that I know are popular on Facebook, too, and I've gotten mixed results.
Try FQL for this;
http://graph.facebook.com/fql?q=select%20url%2C%20id%2C%20type%2C%20site%20from%20object_url%20where%20url%20%3D%20%22http%3A%2F%2Fkriek.hu%2F%22
returns:
{
"data": [
{
"url": "http://kriek.hu/",
"id": 497425470154,
"type": "link",
"site": "kriek.hu"
}
]
}
For more information, see object_url.
I hope it helps!
The ID is given by Facebook only to pages which have a fbshare/like button. Else the API returns the number of shares and the request URL.
If I use the facebook object debugger page I can scrape every url, for example:
https://developers.facebook.com/tools/debug/og/object?q=ddnl.de
The page give me back an url with ID and so I can get every needed parameters.
In this case https://graph.facebook.com/10150164108649475
But I don't get this ID or url with FQL or otherwise?
Very old question, but here's what I found works for me as none of the answers here really resolved my issue:
If you have a custom object tied to a url, the method suggested by Pepe only gives the id FB assigns to the url where type=link. (Which is not tied to any comments)
In my case, I need my custom object id so that I could pull associated comments from it. You can get the object id using FQL by doing a select on 'comments_fbid' from the 'link_stat' table. (This will return the object id even if no comments have been added so it should work for other cases)
api.facebook.com
At this time no of the suggested solutions work for all urls. Only the Debugger is able to get the Graph ID correctly
For example
Debugger:
https://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fwww.amazon.de%2Fgp%2Fproduct%2F3810510793%2F
For URL:
www.amazon.de/gp/product/3442465583/
Result:
https://graph.facebook.com/10150771435736113
{
"url": "http://www.amazon.de/dp/3810510793/ref=tsm_1_fb_lk",
"type": "book",
"title": "Die unwahrscheinliche Pilgerreise des Harold Fry: Roman",
"image": [
{
"url": "http://ecx.images-amazon.com/images/I/51I4E81xrRL._SL160_.jpg"
}
],
"description": "Die unwahrscheinliche Pilgerreise des Harold Fry: Roman",
"site_name": "Amazon.de",
"updated_time": "2012-12-19T16:54:27+0000",
"id": "10150771435736113",
"application": {
"id": "164734381262",
"name": "Amazon",
"url": "https://www.facebook.com/apps/application.php?id=164734381262"
}
}
I had the same problem here, I was trying to get the same data IMDB gets. After almost bang my head against the wall, I decided to look at the facebook's js function. And look what I get, the explanation is on the link.
Getting limited data from a page which has a Facebook ID
Peace