【问题标题】:php script facebook (#100) No permission to publish the videophp script facebook (#100) 没有发布视频的权限
【发布时间】:2015-09-30 07:37:17
【问题描述】:

我正在尝试使用此代码在 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>';

?>

这是来自facebook的回复

    {
       "error": {
      "message": "(#100) No permission to publish the video",
      "type": "OAuthException",
      "code": 100,
      "fbtrace_id": "H1uOf8K83lL"
   }
}

【问题讨论】:

    标签: php facebook video


    【解决方案1】:

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

    1. 首先访问developers.facebook.com
    2. 转到工具和支持并选择图形 API 资源管理器
    3. 然后选择您的应用程序并点击获取访问令牌
    4. 在其中添加权限publish_action并点击确定
    5. 您将获得访问令牌。

    复制该访问令牌并粘贴到

    $access_token = file_get_contents($token_url);
    

    会是这样的

    $access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    

    然后运行你的代码并完成

    【讨论】:

    • 我这样做了,它对一些用户来说效果很好。出于某种原因,我有一些用户仍然收到此错误?有什么想法为什么它只会影响某些人而不影响其他人?
    • @JohnPollard 是的,您获得的访问令牌是有效期为几个小时的临时令牌。您需要创建长期访问令牌。为此,您可以联系stackoverflow.com/questions/10467272/…
    • 此访问令牌是短暂的,您需要立即刷新该令牌。
    • 有一种方法可以获得长寿命的访问令牌
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    相关资源
    最近更新 更多