I'm using the simple code to post on user's wall. This:
$postwall = $facebook->api("/".$id."/feed", 'post', array(
'message' => "test",
'link' => 'http://www.Google.com',
'name' => 'test.',
'description'=> 'test.'
));
This code works but, it's posting with mine facebook name. I want to post with the application name. I searched for authenticating with application name, i tried everything but finally i didn't resolve my problem. Is there anyone who can help me with this please ?
I don't think this is possible. I guess this is the error you'll get:
(#200) Posts where the actor is a page
cannot also include a target_id
What I've done here is that getting the manage_pages permission and then get the application (profile page) access_token and tried to append it to the POST call.
Related
I can't find an example of exactly what I'm trying to do, so sorry if this is a repeated question, but I have looked for the last couple of hours.
I want my Facebook app to be able to update a status or post to a wall of a page that I administrate: http://www.facebook.com/amazingjobsapp as part of a CRON job.
I just can't seem to find any examples on how to do this. Any pointers are greatly appreciated.
EDIT:
I've used to code below and now am getting:
object(FacebookApiException)#11 (8) { ["result":protected]=> array(1) { ["error"]=> array(3) { ["message"]=> string(72) "(#200) The user hasn't authorized the application to perform this action" ["type"]=> string(14) "OAuthException" ["code"]=> int(200) } } ["message":protected]=> string(72) "(#200) The user hasn't authorized the application to perform this action" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(86)
Can someone walk me through granting my app manage_page and publish_stream permissions for page id 413282938687554 please?
EDIT 2: If I look at my graph.facebook.com/me/accounts then it shows the page id above with an access token but if I use that in my code then I still get the error.
You need to get the manages_pages permission
<?php
$attachment = array(
'message' => 'this is my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'http://mylink.com',
'description' => 'this is a description',
'picture' => 'http://mysite.com/pic.gif',
'actions' => array(
array(
'name' => 'Get Search',
'link' => 'http://www.google.com'
)
)
);
// To authenticated user's wall
$result = $facebook->api('/me/feed/', 'post', $attachment);
// To page's wall
$result = $facebook->api('page-id/feed/','post',$attachment);
// To user's wall
$result = $facebook->api('user-id/feed/','post',$attachment);
Ok maybe I missed something in the docs but I found the solution with is as follows:
Note this is for people who are trying to post from a cron job.
Grant the manage_pages, publish_stream and offline_access perms to
your app
Get the access token for your page from me/accounts in the graph api explorer
Add one simple line of code just after you initialize your fb object
$facebook->setAccessToken("XXXXX");
Note the access token needs to be the PAGE access token you got from step 2 and remember if you de-auth the app the access token will change.
Application will need to ask you for manage_pages & publish_stream permissions.
Obtain your pages page_access_token from the graph api /accounts call. Each page you own will have its own token listed. This token can be saved to database or accessed at the time of need. It is not recommended to expose or share this token.
Use "php-sdk" to make the post.
refer to: http://developers.facebook.com/docs/authentication/
refer to: http://developers.facebook.com/docs/reference/php/
NOTE: To impersonate the Page when posting to the wall (i.e. post as the Page, and not the current user), you must use a Page access_token with the manage_pages and publish_stream permissions, as described under Page Access Tokens above.
Example: Assumes user has installed and initialized php sdk for Facebook
<?php
if($user){
$vars = array(
'message' => "message goes here",
// you can uncomment below to enable an image with caption and link.
//'picture' => "image",
//'link' => "Link here",
//'name' => "Name here",
//'caption' => "Caption here",
'show_error' => true,
// comment out the access_token array below to post as a user instead of as page.
array('access_token' => YourPageAccessToken)
);
$testpost = $facebook->api('YourPageId/feed', 'post', $vars);
}
?>
If you find this answer helpful or is correct please remember to mark
it up or mark it as correct, so future users will have an easier time
finding answers.
Ok where I had thought we'd fixed it we haven't the post only works when i'm actually logged into the app itself.
I'm using Shawn's code with all the permissions mentioned with the access token from "me/accounts/" for the AmazingJobs Community page.
I've definitely granted manage_pages, publish stream and offline_acess to my own facebook account i then used the graph api explorer to find the access token within accounts and cut and pasted it into my code. Any ideas?
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 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 a question, It might be found somewhere but I couldnt find a thread for it so if there is one, please post the link.
I admin a page that is a group of several other business areas. I want to post on one page with different icons and names, can that be done? Like different admins but administered by one person/account?
Possible?
What you are going to want to do is use a "Page access_token". To get this you will have to create an application and grant it the manage_pages permission.
You should see in the Authentication Documentation a section called "Page Login".
You can grant your application the manage_pages permission by going to this URL:
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=manage_pages&response_type=token
Don't forget to substitute YOUR_APP_ID and YOUR_URL with the correct values for you application and URL. (the URL can be any URL - it is where Facebook will send you after you close the Dialog). You will see a dialog that looks something like this :
Once you have the correct permission, you'll want to make a call to this URL :
https://graph.facebook.com/me/accounts?access_token=TOKEN_FROM_ABOVE
You will get a response similar to :
As you can see from the image, you will receive a list of all the pages that the user administers along with an access_token for each page.
You use this access_token to make posts on behalf of the page. Since you have not stated what programming language you are using I will give an example in php.
In php, posting to the page would look something like this :
$facebook->setAccessToken(ACCESS_TOKEN_YOU_RETRIEVED_EARLIER);
$attachment = array('message' => 'this is my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'http://mylink.com',
'description' => 'this is a description',
'picture' => 'http://mysite.com/pic.gif',
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
);
$result = $facebook->api('/PAGE_ID/','post',$attachment);
Hope this helps!
Happy coding!
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/