php脚本facebook(100)没有发布视频的权限

php脚本facebook(100)没有发布视频的权限,php,facebook,video,Php,Facebook,Video,我正试图使用此代码在Facebook页面上传视频。我已经添加了添加视频的所有必需凭据。但当我选择视频并点击上传按钮时,json请求显示您没有上传视频的权限。我试图调试这个问题,但没有成功。请帮帮我。多谢各位 <?php $app_id = "xxxxxxxxxxxxxxx"; $app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $my_url = "http://xxxxxxxx/test.php"; $video_title = "tes

我正试图使用此代码在Facebook页面上传视频。我已经添加了添加视频的所有必需凭据。但当我选择视频并点击上传按钮时,json请求显示您没有上传视频的权限。我试图调试这个问题,但没有成功。请帮帮我。多谢各位

 <?php
$app_id = "xxxxxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$my_url = "http://xxxxxxxx/test.php";
$video_title = "test_video_for_app";
$video_desc = "test_description";
$page_id = "xxxxxxxxxxxxxxxx"; // Set this to your APP_ID for Applications

$code = $_REQUEST["code"];

echo '<html><body>';

if(empty($code)) {
  // Get permission from the user to publish to their page. 
  $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=". $app_id . "&redirect_uri=" . urlencode($my_url). "&scope=publish_actions,manage_pages";
  echo('<script>top.location.href="' . $dialog_url . '";</script>');
} else {

  // Get access token for the user, so we can GET /me/accounts
  $token_url = "https://graph.facebook.com/oauth/access_token?client_id=". $app_id . "&redirect_uri=" . urlencode($my_url). "&client_secret=" . $app_secret. "&code=" . $code;
  $access_token = file_get_contents($token_url);

  $accounts_url = "https://graph.facebook.com/me/accounts?" . $access_token;
  $response = file_get_contents($accounts_url);

  // Parse the return value and get the array of accounts we have
  // access to. This is returned in the data[] array. 
  $resp_obj = json_decode($response,true);
  $accounts = $resp_obj['data'];

  // Find the access token for the page to which we want to post the video.
  foreach($accounts as $account) {
       if($account['id'] == $page_id) {
       $access_token = $account['access_token'];
       break;
    }
  }

  // Using the page access token from above, create the POST action
  // that our form will use to upload the video.
  $post_url = "https://graph-video.facebook.com/" . $page_id . "/videos?". "title=" . $video_title. "&description=" . $video_desc. "&access_token=". $access_token;

  // Create a simple form 
  echo '<form enctype="multipart/form-data" action=" '.$post_url.' "  
   method="POST">';
  echo 'Please choose a file:';
  echo '<input name="file" type="file">';
  echo '<input type="submit" value="Upload" />';
  echo '</form>';

}

echo '</body></html>';

?>

经过长时间的研究,我终于找到了解决办法。我们只需要添加developers.facebook.com的权限

首先进入developers.facebook.com 转到工具和支持,然后选择图形api资源管理器 然后选择您的应用程序并单击获取访问令牌 在其中添加“权限发布”操作,然后单击“确定” 您将获得访问令牌。 复制该访问令牌并粘贴以代替

$access_token = file_get_contents($token_url);
就像

$access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

然后运行代码并完成它

我这样做了,对一些用户来说效果很好。出于某种原因,我有一些用户仍然收到此错误?你知道为什么它只会影响一些人而不会影响其他人吗?@JohnPollard是的,你得到的访问令牌是临时令牌,有效期为几个小时。您需要创建长期访问令牌。为此,您可以访问。此访问令牌是短期的,您需要立即刷新该令牌。有一种方法可以获取长期访问令牌
$access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';