I start to code in PHP and I am facing a problem, I used classic method to get User Profil Picture :
https://graph.facebook.com/mark/picture
But as you know, Facebook with little regard for small coders like me. They have cleared this easy method. Now I have to connect on their API to get a facebook profile picture.
I have used fil_get_content on the Mobile Facebook site to retrieve the profile image, but it asks for a captcha.
I am FORCED to go through their API, also I created a APP_ID and APP_SECRET but I do not know how. Despite all the tutorials I've tried these last two hours.
If someone would have a solution, it would be nice.
Thank you, good evening.
Use following Code to get your profile picture
$request = new FacebookRequest(
$session,
'GET',
'/me',
array(
'fields' => 'picture'
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
Now print your response using $response variable.
In a response you got a url.
Related
I have read the instructions here: https://github.com/hwi/HWIOAuthBundle/blob/master/Resources/doc/internals/response_object_and_paths.md
and have copied all the settings.
I am having trouble finding where I can get the response as shown in the instructions as:
/* #var $response \HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface */
var_dump(
$response->getEmail(),
$response->getProfilePicture()
);
I have overridden the ConnectController and have been playing around with it but I dont know how to access the $response given from facebook.
I have tried:
$response = $this->getResourceOwnerByName('facebook')
->getUserInformation($this->container->get('security.context')
->getToken()->getRawToken())->getResponse();
inside the connectAction() method but it doesnt seem to be working.
How can I access the response from facebook so I can grab the user profile data?
Also at what point in the life cycle of the Oautherization is this data sent?
Figured it out.
I can access the $response from my user provider.
In my particular case I have extended overiden the default FOSUserProvider and access the $response here:
AppBundle\Security\Core\User\FOSUBUserProvider::loadUserByOAuthUserResponse()
Im using the Facebook SDK Api [PHP] to post automaticly on a timeline wall.
I created a App and requested the access_token with the following permissions: manage_pages,publish_stream,offline_access.
Im using now the access_token to post the message on a page (/PAGEID/feed) where im moderator.
The following is going OKAY and get the post working under the name of the Facebook page:
$attachment = array(
'access_token' => $accessToken,
'message' => $description,
);
$res = $facebook->api('/PAGEID/feed', 'POST', $attachment);
When Im adding some link + name AND/OR picture it will post not as wall post but as "recent message of others" with as name my own user:
$attachment = array(
'access_token' => $accessToken,
'message' => $description,
'link' => 'http://www.google.nl',
'name' => $description,
'picture' => $image,
);
How can I post full messages with link and picture on the wall self?
If I understand you correctly, you are trying to post as the Page but it's showing up as a post by you. Is that correct?
If so, I think you need to post using the Page's access token, rather than your own access token. Look at the section called "Page Access Tokens" on https://developers.facebook.com/docs/reference/api/page/. Once you get the page's access token using the technique described there, you can set it to be the token that PHP SDK uses by doing $facebook->setAccessToken(.... access token value ...). Then you can do the post and it should show up as having been created by the page.
This problem troubled me for so long. Everything seemed setup correctly but as soon as I added a link, it would post as Admin instead of Page. The answer above by triangle_man solved my problem. When using the PHP sdk, the specific line of code I needed was:
$page_token = $facebook->api("/$page_id?fields=access_token");
I'm posting on my fanpage but i want to do highlight posts. Any suggestions?
I have to star them one by one on the fanpage. Is there any way to do this? I also read the documentation but there is no examples.
http://developers.facebook.com/docs/reference/api/page/#posts
Sample of code:
$args = array(
'access_token' => $page_info['access_token'],
'message' => 'MY MESSAGE'
);
$post_id = $facebook->api("/MY PAGE ID/feed","post",$args);
Im using PHP SDK 3.1.x.
Use:
POST /<post_id>/ with param timeline_visibility = starred
timeline_visibility must be one of the following values: hidden, normal, starred.
Also see https://stackoverflow.com/a/19861323/1784062.
I have such code to post on my friends wall from application
$args = array(
‘message’ => 'my message',
‘name’ => ‘This is my demo Facebook application!’,
‘caption’ => “Caption of the Post”,
‘link’ => $data['view_url'],
‘description’ => ‘this is a description’,
‘picture’ => $body_all["thumb"],
‘actions’ => array(array(‘name’ => ‘View’,
‘link’ => $data['view_url']))
);
$post_id = $facebook->api(“/”.user_$id.”/feed”, “post”, $args);
In array $post_id['id'] facebook returned me id of the post(like that: 100003284224348_121820851270722), and then when i wona to track it, and get some info by ID, i ask FBgraph https://graph.facebook.com/$post_id['id'] but its return false… i have publish_permission, read_streem permission in my application… what i do wrong? why i couldn`t see post in info with id on Facebook graph?
If the graph API GET request is returning false this is usually a tell tell sign that there is an access token issue at the heart of the problem. When you are making the GET request ensure you are using your applications access token.
Try it here: http://developers.facebook.com/tools/explorer/?method=GET&path=100003284224348_121820851270722
It could be a timing issue, where you get back the ID and try to use it before facebook's API can see it. Try waiting a moment and checking. Does it come up in the graph API explorer tool?
I have an Facebook App that is currently posting to a WALL. All the posting are being Titled as MY post. I would like it to be titled by the App. In this documentation, it says there is a 'from' parameter. I've tried to use it a couple of ways and both ways have been unsuccessful. Does anyone have a clue?
https://developers.facebook.com/docs/reference/dialogs/feed/
$attachment = array('message' => $message,
'from' => "<APP_ID>",
//'from' => array('name' => "Sender's Name",'id' => "<APP_ID>"),
}
$me = $this->facebook->api('/me/feed/', 'POST', $attachment);
The from property MUST be a user or a page. You could possibly create a Facebook page with the name of your application and use that.
I've never used the FROM parameter in the Graph API, just on the legacy REST API. And that API parameter was actually actor_id instead of FROM.
Obviously this doesn't solve your problem. To solve your problem, get the access_token for your page from the /me/accounts Graph API end point. When you use this access token, you are identified as the account for which it corresponds, and when you post to /{page_id}/feed with it, it will be posted as the page and in turn be published out to all your users.
<script type="text/javascript">
FB.api("/123123123/feed", "post", {
message: "Test!",
access_token: '184484190795|SDlfkjweifljasdf.3600.123123123.1-2342342|234234234234|XLjsldfjLISJflwieab'
},
function(response)
{
console.log(response);
});
</script>
Thank you all for the suggestions. I finally was able to solve the problem by combining these 2 articles. The basic steps of the first article is still valid. But it is written in the old API. The second article help be get through the step the new REST api couldn't do. Hope this helps.
http://www.emcro.com/blog/2009/01/facebook-infinite-session-keys-no-more/
http://www.alyssapowell.com/2010/10/how-to-generate-an-infinite-session-key-in-facebook/