I'm trying to publish a feed to my users' Facebook wall. I use Facebook Connect for my site. I have generated the link with getLoginUrl() with email, offline_access and publish_stream permissions.
My users' click on this link, authenticate with facebook and comes back to my site. When they do, i'm getting their's ID with getUser().
Then i'm trying to publish a post to their walls. I use this:
$user = $facebook->getUser();
try {
$publishStream = $facebook->api("/$user/feed", 'post', array(
'message' => "Mesaj icerigi",
'link' => 'http://ithinkdiff.net',
'picture' => 'http://thinkdiff.net/ithinkdiff.png',
'name' => 'iOS Apps & Games',
'description'=> 'Checkout iOS apps and games from iThinkdiff.net. I found some of them are just awesome!'
)
);
} catch (FacebookApiException $e) {
print_r($e);
}
But everytime i try to that, i got an error. Api exception or something. What i'm doing wrong?
Related
Here is the my code..
public function autopost(){
$this->load->library('facebook', array(
'appId' => '15704450865*****',
'secret' => '9ef9e145108f7331d677209b62c*****'
));
$user = $this->facebook->getUser();
$access_token = $this->facebook->getAccessToken();
$params = array(
"access_token" => $access_token ,
"message" => "my message goes here.",
"link" => "http://www.sakkigoni.com/",
// "picture" => "http://i.imgur.com/lHkOsiH.png",
"name" => "How to Auto Post on Facebook with PHP",
"caption" => "www.pontikis.net",
"description" => " description goes here."
);
if($user){
try {
$ret = $this->facebook->api('/me/feed', 'POST', $params);
echo 'Successfully posted to Facebook Personal Profile';
} catch(Exception $e) {
echo $e->getMessage();
}
}else{
echo "<a href='".$this->facebook->getLoginUrl(array('scope'=>'email, publish_actions'))."'>Login with Facebook</a>";
}
}
when I run the above code and login on facebook to auto post.Only admin user of app is authorized to post in timeline but other user shows this error
"(#200) The user hasn't authorized the application to perform this action"
i have tried these too but doesn't work in me
same #200 error
same #200 error
If it works for the App admin, but not for anyone else, you probably forgot to send publish_actions through review: https://developers.facebook.com/docs/facebook-login/review
Also, autoposting is not allowed and the message must be 100% user generated. You MUST read the platform policy before creating any App: https://developers.facebook.com/policy/
In other words: You will never get publish_actions approved for autoposting and a predefined message.
I am using php-sdk-4 for facebook wall posting using my app credential. Everything is working fine. Problem is only posting on user facebook wall or through user post on his facebook fan page wall working but when I used his facebook fan page secret code for publish a post on facebook fan wall then show me error :-
(#200) The user hasn't authorized the application to perform this action
My facebook app in testing mode
I am doing all these steps as admin.
In my project I want functionality user come login through facebook and select his facebook fan page and publish some text or image on his facebook fan page
Code :-
$facebook = new Facebook(array(
'app_id'=>'XXXXXXXXXX',
'app_secret'=>'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'default_graph_version' => 'v2.5'
));
$graph_url_pages = "https://graph.facebook.com/me/accounts?access_token=".$accessToken;
$pages = json_decode(file_get_contents($graph_url_pages)); // get all pages information from above url.
for($i=0;$i<count($pages->data);$i++)
{
$page_token = $pages->data[$i]->access_token;
$pageId = $pages->data[$i]->id;
$params = array(
'access_token' => $page_token,
'from' => 'XXXXXXXXXXX',
'to' => $pageId,
'message' => 'Google Inc',
'link' => 'http://www.google.com/',
);
try {
$response = $facebook->post('/'.$pageId.'/feed', $params);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
print_r($graphNode);die;
}
In code when I passed access_token then show me error but when I passed $accessToken (user access token) then user post going on facebook fan page wall but I want facebook fan page publish a post on timeline.
I'm developing with Laravel a package to post on facebook. My code responsible for obtaining and storing the access token of the page post a link besides test makes this operation correctly with an app that I have created test fb . The problem is to create another app on facebook to put it into production , this second app facebook created it with the same configuration that does work but when publishing gives me the following error: (# 200 ) The user hasn 't Authorized the application to perform this action .
This is the code snippet I use for testing .
public function getTest(){
//$accessToken = new AccessToken($this->getParam('TOKEN'));
try {
$page_post = (new FacebookRequest($this->session, 'POST', '/'.$this->getParam('PAGE_ID').'/feed', array(
'access_token' => $this->getParam('TOKEN'),
'link' => 'link',
'description' => 'Hola mundo desde laravel',
'picture' => 'link/img.png',
'message' => 'Messge',
) ))->execute()->getGraphObject()->asArray();
// return post_id
print_r( $page_post );
} catch(FacebookSDKException $e) {
var_dump($this->getParam('TOKEN'));
echo $e->getMessage();
// var_dump($e);
exit;
}
As for the authorization of the application is correctly even when you enter to view user applications see 2 ( The works and which not) , both with the same permissions accepted.
Fixed , I lacked a permit : ' publish_pages '
$params = array(
'scope' => 'manage_pages','publish_actions','publish_stream','publish_pages'
);
Is there a possibility where I can make a button on which when I click, the contents directly get shared on facebook without showing our user the share prompt dialog box?
I referred it online and found that its possible through mobile devices:
http://www.mindfiresolutions.com/How-to-post-message-on-your-facebook-wall-without-using-Facebook-dialog-Box-1419.php
The question is can we make some sort of ajax call and get this done on web apps.
We used Following code
<?php
require_once('php-sdk/facebook.php');
$config = array(
'appId' => 'My app ID', /*Your APP ID*/
'secret' => 'My Secret ID', /*Your APP Secret Key*/
'allowSignedRequest' => false
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
if($user_id) {
try {
$user_profile = $facebook->api('/me','GET');
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl();
echo 'Please login.';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, print a link for the user to login
$login_url = $facebook->getLoginUrl();
echo 'Please login.';
}
$response = $facebook->api(
"/me/feed",
"POST",
array (
'message' => 'This is a test message',
'link' => 'www.google.com'
/* 'picture' => '{picture}',
'caption' => '{caption}',
'description' => '{description}'*/
)
);
?>
But its returns : " Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action throw in file"
Any help would be highly appreciated.
Thanks in advance.
Of course you can using the Graph API. On the button click you just have to make a \POST call to /me/feed.
Learn more about publishing a feed via Graph API and what all parameters are available here.
Permission required: publish_stream
Using PHP SDK:
$response = $facebook->api(
"/me/feed",
"POST",
array (
'message' => 'This is a test message',
'link' => '{link}',
'picture' => '{picture}',
'caption' => '{caption}',
'description' => '{description}'
)
);
Direct HTTP Request-
POST /me/feed
Host: graph.facebook.com
message=This+is+a+test+message
...
You can check your calls in Graph API Explorer
Edit:
To ask for the required permissions:
$params = array(
'scope' => 'publish_stream'
);
$login_url = $facebook->getLoginUrl($params);
You can read more about permissions here.
Try this way: https://developers.facebook.com/docs/reference/php/
When coding the wep app, you only have to provide the App Id and the App Secret, then you should have to specify the content to be posted.
You should try also the Javascript Facebook SDK, you'll find it here: https://developers.facebook.com/docs/javascript or you could go further and try the C# SDK, this one is a little bit more complex, but you will be able to do so much more.
Have fun coding!!!
Just go to https://developers.facebook.com/docs/opengraph/
Review it and place what kind of share you want.
This is the long process to be handle so. you need to study it.
I am trying to make a post on the user's Facebook wall using my application. I also want to be able to access and display the person's user information afterward - but I'm getting stuck.
The code I have so far is below (with the sensitive parts masked, of course):
<?php
include("src/facebook.php");
$facebook = new Facebook(array(
'appId' => ##############,
'secret' => #####################################,
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
// The access token we have is not valid
$user = null;
}
}
if (!$user) {
$args['scope'] = 'offline_access, read_stream, friends_likes, email, read_stream, publish_stream, user_birthday,user_hometown, user_photos, uid, username, first_name';
$loginUrl = $facebook->getLoginUrl($args);
}
if (!$user): ?>
Login with Facebook
<?php endif ?>
I can't figure out what's going wrong - and maybe I'm missing something critical? Any guidance would be appreciated.
1) make sure to read the permissions documentation. For instance, offline_access has been deprecated and most of the permissions you are asking for does not exists!
2) to post on the user wall you need the publish_stream permission (which you are already requesting)
3) follow my tutorial, something like the below will get you started:
$args = array(
'message' => 'Hello from my App!',
'link' => 'http://www.masteringapi.com/',
'caption' => 'Visit MasteringAPI.com For Facebook API Tutorials!'
);
$post_id = $facebook->api("/me/feed", "post", $args);
4) improve your view (mixing PHP and HTML in your above code is not programmatically wrong but not recommended). And to answer your last request, the $user_profile would hold the information you need, just check the Facebook example to get started.
5) try to improve your English and welcome to Stack Overflow!