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
Related
I have 2 test users in facebook.
I want to make them friends using Facebook Graph API:
https://graph.facebook.com/v2.6/user1_id/friends/user2_id?access_token=user1_access_token
method: post
I get error:
{
"error": {
"message": "(#33) This object does not exist or does not support this action",
"type": "OAuthException",
"code": 33,
"fbtrace_id": "A7EHydY_B4x......."
}
}
Can someone please help?
Thanks.
https://developers.facebook.com/docs/graph-api/reference/v6.0/test-user:
An app access token is required to update these fields for any test users associated with that app.
You need to use your app access token for this, not a user token.
Can I get the access token without login? As I need to get the ratings by below API and this API i required access_token.
https://graph.facebook.com/v5.0/{page-Id}/ratings?access_token={page_access_token}
Below steps I have done it to achieve the ratings.
First API Call
https://graph.facebook.com/oauth/access_token?client_id={client-id}&client_secret={client-
secret-id}&grant_type=client_credentials
Second API calls
https://graph.facebook.com/debug_token?input_token={user_access_toke}
&access_token={generated_access_token_from_ouath}
Error:
{
"error": {
"message": "(#100) The App_id in the input_token did not match the Viewing App",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "AFBYAMTvW5W65Ur3gUXa_0e"
}
}
Can you please help me out to generate the access token so I can get the rating and reviews.
For Ratings, you need to use a Page Token. A Page Token can only be generated with a User Token, and you do need to login for that. Without any login, Facebook does not know if you own the Page - which is required to read the Ratings with the API.
Information about Tokens and how to generate them:
https://developers.facebook.com/docs/facebook-login/access-tokens/
https://www.devils-heaven.com/facebook-access-tokens/
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
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.
I am learning Rest web services using Postman extension of Chrome. I'm practicing it using Facebook API. I have a question about posting in FB.
URI used: https://graph.facebook.com/me/feed?
In the Body of the POST Method, I have given the following Json content
{
"message": "hello",
"access_token": "<a valid token>"
}
I am very sure that my access token is correct as when I append the access token and message with the above URI, the status gets posted successfully. Also when I use it as key-value pairs in 'x-wwww-form-urlencoded' section, it works fine.
But when I try to update the status using the Body of the POST method with the JSON content mentioned above, it tells
{ "error": { "message": "An active access token must be used to query information about the current user.", "type": "OAuthException", "code": 2500 } }
Is there any thing wrong in the format of the JSON content
I missed content-type=application/json
in the Header section.
Adding this solved the problem