php - 无法在用户时间轴上发布
问题描述
如何使用 php sdk 在用户时间轴上发布
我在stackoverflow上搜索这个问题我没有得到任何plx帮助我需要为我的客户做这件事
<?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) 如果发布到群组,则需要在群组中安装应用程序,并且 \ 具有用户令牌的 publish_to_groups 权限,或者具有页面令牌的 manage_pages \ 和 publish_pages 权限;如果发布到页面,\ 要求 manage_pages 和 publish_pages 作为管理员在 E:\xampp\htdocs\Social_Platform\vendor\facebook\graph-sdk\src\Facebook\Exceptions\FacebookResponseException.php:137 中有足够的管理权限跟踪:#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->
解决方案
不能再发布到用户墙了。所需的权限“publish_actions”不久前被弃用:
https://developers.facebook.com/docs/graph-api/changelog/break-changes#login-4-24
改用共享对话框:https ://developers.facebook.com/docs/sharing/reference/share-dialog
推荐阅读
- apache-spark - 检查一列是否全部为空
- python - 如何在 Airflow 的 PythonOperator 的 python_callable 中提供异步函数?
- elasticsearch - 需要有关如何解决 Elastic OOM JVM 崩溃问题的建议
- asp.net - 如何使用 SFTP 部署 Net Core razor pages 应用程序?
- ios - 强制 YTPlayerView 以编程方式退出全屏
- python - Windows“路径”环境变量如何工作?
- java - 如何在 Java 中删除标点符号但保留首字母缩写词和连字符?
- ruby-on-rails - 如何修复 Rails 服务器启动时冻结或无法继续启动
- go - 如何在不重复的情况下测试功能?
- linux - Bash 循环只读取最后一行