I an facing an issue with the Facebook SDK POST action when posting a very basic message on my page which is linked to my Twitter account. I have tried to solve the issue by myself using Google and StackOverflow, but I didn't manage to find a fix.
The issue is the following:
When I post a message with the SDK:
It appears in the page and is visibe by myself
It appears in the page also for other Facebook user
It appears in the Facebook Feed
but the message is not transmitted to my Twitter account
When it post something "manually" it is correctly sent to my Twitter account. The issue only appears when using the SDK. Hereafter you can find my code and the context of my request:
I am using a PHP script on my personal desktop (WAMP server).
The attachement is very very basic: 'message' => "Hello dear followers!"
The application used to post is not in sandbox mode.
Your app detail page has not yet been submitted for review.
The message appears as public on the page and is indeed visible by other users.
When I post manually the exact same message, it is correctly sent to Twitter.
Can you help me with this issue? Many thanks and all the best.
$appid = *(hidden)*;
$appsecret = *(hidden)*;
$pageId= *(hidden)*;
$facebook = new Facebook(array('appId' => $appid,'secret' => $appsecret,'cookie' => false));
$user = $facebook->getUser();
if($user){
try{
$page_info = $facebook->api("/$pageId?fields=access_token");
if (!empty($page_info['access_token'])){
$attachment = array(
'access_token' => $page_info['access_token'],
'message' => "Hello dear followers!",
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);
$status = $facebook->api("/$pageId/feed", "post", $attachment);
}
}
}
The issue appears because of the special action item:
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
Removing this specificity the message is transmitted to Twitter, successfully.
Related
I made a script in which automatically put in a fan page on facebook, the script works, but the post is only visible to the user who posted (which is the admin of the fan page), the login'm asking permissions below:
$loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,publish_stream'));
And I'm posting with the following code:
$args = array(
'access_token' => $page_info['access_token'],
'link' => 'http://www.sitelink.com.br/alguma-coisa',
'method' => 'post'
);
$facebook->api("/99999999999/feed","post",$args);
Does anyone know if the login I have to ask some permission to appear as the most public posts?
I have to configure something else in there in the facebook app developers?
I'm having a problem when trying to post a link to a friends wall using the Facebook graph from my application.
I am currently using the Facebook SDK for PHP, I have no problems posting to the wall of the user that's logged in but cannot post to friends of the logged in user.
I have requested the extended permission "publish_stream" and here is the code am I using:
$args = array('message' => $message,
'link' => 'google.com',
'name' => 'Test!',
'caption' => 'Please click on the link',
'description' => 'description');
$result = $facebook->api("/$friendId/feed", 'POST', $args );
$friendId has the facebook id of the friend of the logged in user, any help would be much appreciated.
A quick scan of the FB API reference shows that you can set the to key value pair in this operation to
mention or target a user in this post
I want to post to facebook page wall as a page using PHP. I've got access_token by below links.
https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=123456789&redirect_uri=http%3A%2F%2Fmysite.net&scope=publish_stream,manage_pages,offline_access
https://graph.facebook.com/me/accounts?access_token=...
I'm using this simple code:
$appid = "";
$secret = "";
$pageid = "";
$access_token = "";
require_once("facebook-php-sdk/src/facebook.php");
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $secret
));
try {
$args = array(
'access_token' => $access_token,
'message' => 'Test',
'link' => 'http://www.test.com',
'description' => 'Test'
);
$post_id = $facebook->api("/$pageid/feed","post",$args);
} catch (FacebookApiException $e) {
error_log($e);
}
And that's the error I'm getting:
OAuthException: (#200) Posts where the actor is a page cannot also include a target_id
But posting /me/feed won't work neither. All solutions I've googled don't work anymore, official documentation didn't help. I got it working when posting as a user (not a page) and with javascript api (required 'share' click action by a user).
Anyone knows the solution for automatic post to a fb page as a page? Spent couple of frustrating days trying to figure it out -_-
Thanks,
A.
I've had the same problem. The reason was that I was an admin of more than one page, and I tried to post with the token of another page.
Pages cannot post to user's walls (that's why you're getting the OAuthException that says "as a page, you cannot set the target_id"). You'll have to first create an application and get the user's permission (publish_stream) to post to their feed via said app.
I assume you have some knowledge of app and how posting work.
1.You have to get Page access token and use this on array.
2.you use this
"/$pageid/feed"
try use this
$facebook->api($pageID . '/feed','POST'
Thanks...
I must be missing something really obvious.
I have created successfully an Event with the graph API
I now want to put a link on the event page
When i use the code below, it creates a message but not a link. So please someone what am i missing. I do get a linkid back as well as you can see the message on the page.
So this is the pretty simple code.
$fb = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookie' => true,
'fileUpload' => true
));
$fb->setAccessToken($_SESSION[ $eid.'_FB_USER_ACCESSCODE' ]);
$data = array( 'access_token' => $_SESSION[ $eid.'_FB_USER_ACCESSCODE' ],
'link' => 'http://www.thedomain.com',
'message' => "To purchase your tickets"
);
$result = $fb->api($newFBEventId."/feed","post",$data);
Thanks
This is a Bug and its reported and marked as confidential
With the below text and its also contain security hole
bug report link
Below is my bug report text.
Other details on this report are shown to Facebook employees only
I recently attempted to post on an event's wall using the Graph API, but only the message is posted; Everything else is not showing. e.g.
Link
Picture
etc
There is one more big thing that the post doesn't show; That this post is post "via a Facebook app"
Note: posting on a page or user wall worked and also normal messages posted on an event 's wall.
The most important thing is when the post is shown on the event's wall "it does not show that its posted by a Facebook Application".
This is very dangerous; For example I can make an application and post nonsense on a user's event wall. People will think that this is posted by the user.
Thanks
I have a website, and I need it to post status updates to a Facebook Page from time to time.
Using my personal Facebook account, I created an App, and a Page. So far, I've been able to programmatically post to my Page's Wall, by adding this code to my website:
include_once "lib/facebook/src/facebook.php";
$facebook = new Facebook(array('appId' => 'APP_ID_HERE', 'secret' => 'APP_SECRET_HERE'));
if($facebook->getUser()) {
try {
$ret_obj = $facebook->api('/FACEBOOK_PAGE_ID_HERE/feed', 'POST', array(
'link' => 'www.example.com',
'message' => 'Posting with the PHP SDK!',
'access_token' => 'FACEBOOK_PAGE_ACCESS_TOKEN_HERE'
));
echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
} catch(FacebookApiException $e) {
// user logged out (has user_id, but invalid access token)
$login_url = $facebook->getLoginUrl(array('scope' => 'publish_stream'));
echo 'Please login.';
}
echo '<br />logout';
} else {
$login_url = $facebook->getLoginUrl(array('scope' => 'publish_stream'));
echo 'Please login.';
}
So I just open my website, click "Please login", login as myself. Once I'm logged it, it will now be able to post the status update to the Facebook Page.
Obviously, the problem here is that I need to be logged in for it to be able to post. If other users will try to login with their user accounts, my website cannot post status updates to the Facebook Page because I am the only Admin for the app/Page.
My question is, is there a way for me to programmatically log myself into Facebook so I can do these status updates to my Page automatically?
Sorry, total noob here to Facebook development.
Seems like you need to update status while you are offline from facebook. To do this you need to get the offline access permission of the app user and you need to have a "infinite" token for facebook app to access the APIs, so that your program can update anytime you want with out logging into facebook.
You may get something you want here
http://developers.facebook.com/docs/authentication/
I'm a little late to the party here, but I thought I'd post my gist example for how to do something very similar. I added some functionality to fbconsole to make it easy to programmatically login with fbconsole.automatically_authenticate to make it much easier to access this information in a systematic way. This addition has not yet been incorporated into the master branch of fbconsole (it was just posted this morning), but it is available here in the meantime for those that are interested.
This is what I use to do,
// = SET WALL DATA HERE ===============
$attachment = array(
'access_token' => 'My Access token here',
'message' => '',
'name' => 'My Wall Post Header/Title Here',
'caption' => 'Small caption here',
'link' => 'http://www.mywebsite.org',
'description' => 'Wall Post Details Here',
'picture' => "http://www.mywebsite.org/images/logo.gif",
);
// =POST ON FACEBOOK WALL ==========================
$this->facebook->api('/me/feed', 'POST', $attachment);
, $attachment);
So include your Facebook API, Get your Facebook Access token, SET data for your wall post and call for facebook api with me/feed method.
This will make a wall post on your wall without asking for login.
make sure you are using correct Access Token.