无法在用户时间线上 post
Cant post on users timeline
如何使用 php sdkpost 在用户时间线上
我在 Whosebug 上搜索了那个问题,我什么也没得到请帮忙
我需要为我的客户做这个
<?php
namespace App;
use Facebook\Facebook;
class FacebookClass{
private $fb;
private $appiD = 3073019182770120;
private $appSecret = "6360e1540e1add2b6fc93fce07fcb61a";
public function __construct()
{
$this->fb = new Facebook([
'app_id' => $this->appiD, // Replace {app-id} with your app id
'app_secret' => $this->appSecret,
'default_graph_version' => 'v4.0',
]);
}
public function getLoginUrl() {
$helper = $this->fb->getRedirectLoginHelper();
$permissions = ['email']; // Optional permissions
$loginUrl = $helper-
>getLoginUrl('http://localhost/social_platform/',$permissions);
return $loginUrl;
}
public function loginWithFacebook() {
$helper = $this->fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
if(isset($accessToken))
{
$_SESSION['facebook']['access_token'] = (string) $accessToken;
header("index.php");
}
} catch (\Throwable $th) {
// var_dump($th);
}
}
public function postOnUserTimeLine() {
// posting on user timeline using publish_actins permission
try {
// message must come from the user-end
$data = ['message' => 'testing...'];
$request = $this->fb->post('/me/feed', $data,
$_SESSION['facebook']['access_token']);
$response = $request->getGraphNode()->asArray;
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
echo $response['id'];
}
}
?>
致命错误:未捕获 Facebook\Exceptions\FacebookAuthorizationException:(#200) 如果 post 加入一个组,需要在该组中安装应用程序,并且 \ 具有用户令牌的 publish_to_groups 权限,或 manage_pages \ 和 publish_pages 权限与页面令牌;如果 post 访问页面,\ 需要 manage_pages 和 publish_pages 作为管理员,在 E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\Exceptions\FacebookResponseException.php:137 Stack 中具有足够的管理权限跟踪:#0 E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\FacebookResponse.php(210): Facebook\Exceptions\FacebookResponseException::create(Object(Facebook\FacebookResponse)) #1 E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\FacebookResponse.php(255): Facebook\FacebookResponse->makeException() #2 E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\FacebookResponse.php(82): Facebook\FacebookResponse->deco in E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\Exceptions\FacebookResponseException.php 第 137 行
无法再发布到用户墙上。所需权限 "publish_actions" 不久前已弃用:
https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#login-4-24
改为使用共享对话框:https://developers.facebook.com/docs/sharing/reference/share-dialog
如何使用 php sdkpost 在用户时间线上
我在 Whosebug 上搜索了那个问题,我什么也没得到请帮忙 我需要为我的客户做这个
<?php
namespace App;
use Facebook\Facebook;
class FacebookClass{
private $fb;
private $appiD = 3073019182770120;
private $appSecret = "6360e1540e1add2b6fc93fce07fcb61a";
public function __construct()
{
$this->fb = new Facebook([
'app_id' => $this->appiD, // Replace {app-id} with your app id
'app_secret' => $this->appSecret,
'default_graph_version' => 'v4.0',
]);
}
public function getLoginUrl() {
$helper = $this->fb->getRedirectLoginHelper();
$permissions = ['email']; // Optional permissions
$loginUrl = $helper-
>getLoginUrl('http://localhost/social_platform/',$permissions);
return $loginUrl;
}
public function loginWithFacebook() {
$helper = $this->fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
if(isset($accessToken))
{
$_SESSION['facebook']['access_token'] = (string) $accessToken;
header("index.php");
}
} catch (\Throwable $th) {
// var_dump($th);
}
}
public function postOnUserTimeLine() {
// posting on user timeline using publish_actins permission
try {
// message must come from the user-end
$data = ['message' => 'testing...'];
$request = $this->fb->post('/me/feed', $data,
$_SESSION['facebook']['access_token']);
$response = $request->getGraphNode()->asArray;
} catch (Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
echo $response['id'];
}
}
?>
致命错误:未捕获 Facebook\Exceptions\FacebookAuthorizationException:(#200) 如果 post 加入一个组,需要在该组中安装应用程序,并且 \ 具有用户令牌的 publish_to_groups 权限,或 manage_pages \ 和 publish_pages 权限与页面令牌;如果 post 访问页面,\ 需要 manage_pages 和 publish_pages 作为管理员,在 E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\Exceptions\FacebookResponseException.php:137 Stack 中具有足够的管理权限跟踪:#0 E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\FacebookResponse.php(210): Facebook\Exceptions\FacebookResponseException::create(Object(Facebook\FacebookResponse)) #1 E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\FacebookResponse.php(255): Facebook\FacebookResponse->makeException() #2 E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\FacebookResponse.php(82): Facebook\FacebookResponse->deco in E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\Exceptions\FacebookResponseException.php 第 137 行
无法再发布到用户墙上。所需权限 "publish_actions" 不久前已弃用:
https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#login-4-24
改为使用共享对话框:https://developers.facebook.com/docs/sharing/reference/share-dialog