Facebook: Can't publish on user feed in test mode - facebook

I have developed a Facebook app in test mod and I want to publish on the test user's wall.
this is the link where the user register and accept the permissions:
https://www.facebook.com/dialog/oauth?type=user_agent&client_id=MY_APP_ID&display=popup&redirect_uri=THE_URL&scope=email%2Cpublish_actions
After that I am getting an some sort of a token, using this token I am doing the following request to the graph:
/oauth/access_token?client_id=MY_APP_ID&client_secret=MY_APP_SECRET&grant_type=fb_exchange_token&fb_exchange_token=".$token
the token coming back is now being used by me to get the user's details from the graph:
/me/?$user_access_token&fields=name,age_range,id,email,gender,currency,locale,timezone"
I am getting in result all the fields listed above. (one strange thing, the id coming back is not the test user's public id, the other field are correct...)
when I want to post so someones wall I am running this int the graph:
/oauth/access_token?client_id=MY_APP_ID&client_secret=MY_SECRET&grant_type=client_credentials
the token coming back will be used here:
$token = self::getAccessToken($app_id,$app_secret);
$post_array = array();
$post_array['access_token'] = $token;
$post_array['message'] = urlencode($message);
$post_array['link'] = urlencode($link);
$res = self::post("https://graph.facebook.com/".$user_id."/feed?",$post_array);// the user id might be wrong?
and I am getting the following error:
{"error":{"message":"(#200) Permissions error","type":"OAuthException","code":200,"fbtrace_id":"EO5WvMfYYgC"}}
What can it be?
the fact that I am in test mod?
or maybe the user's ID i got back is wrong?
Thanks

The ID is correct, you only get an "App Scoped ID". You are not supposed to use the global/public ID anymore, and you should use /me/feed for posting, not /user-id/feed. You can only post on the wall of the authorized user anyway.

Related

Facebook Matching API - Page Scoped ID (PSID) empty for other users

I have a bunch of users registred on my website thanks to Laravel Socialite and Facebook Login. When a user creates a account their app_scoped_id is save under provider_user_id.
I need to get the page_scoped_id of a user on my page instead of app_scoped_id.
To do so I am using the Facebook Matching ID whose documentation could be find here
The code
$fb = new Facebook(...);
$response = $fb->get($user->socialAccount->provider_user_id . '/ids_for_pages?fields=id&page=' . env('FB_PAGE_ID'), env('FACEBOOK_PAGE_TOKEN'));
$pageScopedId = $response->getDecodedBody()['data'][0]['id'];
Issue
It works perfectly for myself, but when I'm trying to get other users' page scoped id, it returns an empty array.
The Facebook Matching API is able to match page scoped id and app-scoped id if and only if they both exist.
In my case, page scoped id has not been associated with users (since they have not interacted with the messenger yet).

Combining selenium with facebook api and making request

I have 3 questions: 1)Can I combine facebook login via mozila browser(selenium) with facebook graph api, for example:
browser=webdriver.Firefox()
browser.get('https://facebook.com')
user=browser.find_element_by_id('email')
user.send_keys('email')
password=browser.find_element_by_id('pass')
password.send_keys('pass')
login=browser.find_element_by_id('u_0_r')
login.click()
graph = facebook.GraphAPI(token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")
friend_list = [friend['name'] for friend in friends['data']]
print (friend_list)
2)Can somebody help me with login on facebook through app_id, secret_id and token, or through email and password
3)I want to get profile info, for example with help of get_object, but I need to know user's id to do it. How can I get this id, if I have only page url's, or I can use part after facebook.com/ to do this request?
P.s. If u know answer at least on one of this questions, pls right it in comments or in answers, it will be very useful:)

Facebook Graph private profile picture

So I am trying to create a register from facebook script and I am testing with my own Facebook account.
This is what I am doing:-
I am hitting this link to get access token:-
https://www.facebook.com/dialog/oauth?client_id=APP_ID_HERE&redirect_uri=URI_HERE&scope=email
$graph_url = "https://graph.facebook.com/me?access_token="
. $params['access_token'];
$user = json_decode(file_get_contents($graph_url));
var_dump($user);
I am getting all the information that I need but I am not getting profile picture. I think this is because my profile picture is private. How do I get the profile picture even if its private. Do I have to add more permission scope?
The user photo is never returned when just making a request to the /me endpoint. In order to get the Users profile photo you have two options.
1) Using the 'fields' parameter you can request the users picture. e.g your request will become:
https://graph.facebook.com/me?fields=picture&access_token=<ACCESS_TOKEN>
2) You can also use the 'picture' edge on the user node which is described more here. This will make your request look like:
https://graph.facebook.com/me/picture?access_token=<ACCESS_TOKEN>
Once you have an access token for a user then there is no extra scope needed in order to get the profile picture.

Get friends of a User using Facebook API

I am facing a problem in fetching the friends of a user. The following code is working fine when "me" is passed as an UID. But it doesn't work when a user id is passed like 523621551. Every thing is set in the permissions. And i get the "Unsupported operation" error. Following is the code.
public function getAllFriends($uid) {
return $this->fb->api("/" . $uid . "/friends", 'GET', array(
'access_token' => $this->fb->getAccessToken())
);
}
So, what is causing this problem?
I also studied other related questions but those didn't help. :(
You can´t get the friends of ANY user, you can only get the friends of the user who is authorized at the moment. The docs are a bit misleading, it may only work with the (app scoped) user id of the authorized user, but it will never work with any other user id - that request is "unsupported" ;)
Also, you can only get the users who authorized the same App too, just in case you don´t know yet. See changelog: https://developers.facebook.com/docs/apps/changelog
Edit: I just tested it with an App Scoped ID in the API Explorer and it works, so i assume you are trying to get the friends of another user as i expected - which is not supported, of course.
I also tested it with the "real" ID of the authorized user and got the following error:
The global ID 1603196280 is not allowed. Please use the application
specific ID instead.
Makes sense, you would not get the global ID in the App anyway, only App Scoped IDs. As i said, the error you get is not very clear but correct: Getting the friends of ANY user is "unsupported".

restfb api not support when user logout from facebook & access key generate every time

I am using RESTFb api to post a message on facebook wall
my code is:
val facebookClient: FacebookClient = new DefaultFacebookClient("access_key")
def publishMessage(msg:Mesage): String = {
val publishMessageResponse: FacebookType = facebookClient.publish("me/feed", classOf[FacebookType],
Parameter.`with`("message", msg))
publishMessageResponse.getId()
}
But this code is working only when I am login in my facebook account.If I am not login it give me the error of "user session logout". and it told me to generate the access token every time.
Thats because you are trying to post to your own Wall.. thats why, OAuth needs to validate you are logged otherwise it wont post anything... if you where posting to a PAGE... well that's diferent you could use APP and SECRET ID's to generate AccessTokens on your website.