我想使用hybridauth在Facebook墙上分享。社交登录非常有效,但是问题是,当我使用setUserStatus()在Facebook墙上张贴一些消息时,它给出了错误,但是此代码非常适合 Twitter 。我也搜索了很多Google共享墙,但没有找到任何教程。请告诉我们如何在Google Plus上分享。
错误:
Fatal error: Uncaught Hybridauth\Exception\HttpRequestFailedException: Signed API request has returned an error. HTTP error 403. Raw Provider API response: {"error":{"message":"(#200) Requires either publish_actions permission, or manage_pages and publish_pages as an admin with sufficient administrative permission","type":"OAuthException","code":200,"fbtrace_id":"CbU\/8WTnigM"}}. in C:\xampp\htdocs\testphase-wholesale\hybridauth\src\Adapter\AbstractAdapter.php:360 Stack trace: #0 C:\xampp\htdocs\testphase-wholesale\hybridauth\src\Adapter\OAuth2.php(682): Hybridauth\Adapter\AbstractAdapter->validateApiResponse('Signed API requ...') #1 C:\xampp\htdocs\testphase-wholesale\hybridauth\src\Provider\Facebook.php(235): Hybridauth\Adapter\OAuth2->apiRequest('https://graph.f...', 'POST', Array) #2 C:\xampp\htdocs\testphase-wholesale\example\home.php(126): Hybridauth\Provider\Facebook->setUserStatus(Array) #3 {main} thrown in C:\xampp\htdocs\testphase-wholesale\hybridauth\src\Adapter\AbstractAdapter.php on line 360
注意:在 Localhost 上工作。 setUserStatus()在Twitter上可以完美运行。
if (isset($_POST['btn_post_message'])) {
$message = $_POST['message_text'];
// init hybridauth
$hybridauth = new Hybridauth($config);
// try to authenticate with twitter
$adapter = $hybridauth->authenticate($provider);
if($provider == 'Facebook') {
// update the user status or post to wall
$adapter->setUserStatus(
array(
"message" => $message, // status or message content
"link" => "sdf" // a picture link
));
} else{
// update the user status
$adapter->setUserStatus($message);
}
}
Config.php
<?php
/**
* Build a configuration array to pass to `Hybridauth\Hybridauth`
*/
$config = [
/**
* Set the Authorization callback URL to https://path/to/hybridauth/examples/example_06/callback.php.
* Understandably, you need to replace 'path/to/hybridauth' with the real path to this script.
*/
'callback' => 'http://localhost/testphase-wholesale/example/callback.php',
'providers' => [
'Twitter' => [
'enabled' => true,
'keys' => [
'key' => '...',
'secret' => '...',
],
],
'Google' => [
'enabled' => true,
'keys' => [
'id' => '',
'secret' => '',
],
"scope" => "https://www.googleapis.com/auth/plus.login ". // optional
"https://www.googleapis.com/auth/plus.me ". // optional
"https://www.googleapis.com/auth/plus.profile.emails.read", // optional
],
'Twitter' => [
'enabled' => true,
'keys' => [
'id' => '=',
'secret' => '',
],
"scope" => "email", // optional
],
'Facebook' => [
'enabled' => true,
"scope" => "email,user_gender, user_friends, user_birthday, user_age_range, user_hometown, user_link, user_location",
"trustForwarded" => false,
'keys' => [
'id' => '',
'secret' => '',
],
],
],
];