我正在尝试设置这个基本上传版本,允许用户将视频直接上传到我的Facebook群组,但是我遇到了用户访问令牌的问题,它会抛出错误“格式错误的访问令牌”
我从Facebook图形api资源管理器中抓取了一个用户访问令牌,并将其硬编码到URL中,一切正常
我对这个问题可能有什么想法
我的代码:
$app_id = "APP_ID";
$app_secret = "APP_SECRET";
$my_url = "http://DOMAIN/post.php";
$video_title = "TITLE FOR THE VIDEO";
$video_desc = "DESCRIPTION FOR THE VIDEO";
$group_id = "GROUP";
$code = $_REQUEST["code"];
echo '<html><body>';
if(empty($code)) {
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=publish_actions";
echo('<script>top.location.href="' . $dialog_url . '";</script>');
}
$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);
$post_url = "https://graph-video.facebook.com/".$group_id."/videos?access_token=".$code."&"."title=".$video_title."&description=".$video_desc;
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>';
错误是:
{
"error": {
"message": "Malformed access token AQDDR2mYCEP3F4MvRoBbHBhNViCPkdBhYu0IFyD3pkopzmIZlug69tzb3Cl7E1Z_5qzMTPBAnzMREGm0hU9Nym3EaIMCBelwhKOLwxSTQwStbZ7euPOxPLrfi9-JYSnJcjvy3K_13Ov14IaybzXfXhjNHLzZNuyofnFPbLVieYvOjfpT9UJSzS9TB6Plttbt0O4aKtnG9RkTaoNkJkwUgCw9IGV_dWw5vF77CrhyGxJ5B7quOZPjz39f5QtJ50X5njZE2C4jysMhg1Xfdg9vAhfaFYYEg4f_WrxVfF2QnHINHLLfhFbzSW74jJnEBoVszseA46nqWG4mnrgrs9K97jQ0iqc0UnCEY1JU92D94fX_kw",
"type": "OAuthException",
"code": 190,
"fbtrace_id": "DCS2/KjriCI"
}
}
答案 0 :(得分:0)
我清理了访问令牌并将其放在帖子网址中,现在一切正常
$app_id = "[APP_ID]";
$app_secret = "[APP_SECRET]";
$my_url = "[URL_TO_THIS_SCRIPT";
//$video_title = "TITLE FOR THE VIDEO";
//$video_desc = "DESCRIPTION FOR THE VIDEO";
$group_id = "[GROUP_OR_PAGE_ID]";
$code = $_REQUEST["code"];
echo '<html><body>';
if(empty($code)) {
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=publish_actions";
echo('<script>top.location.href="' . $dialog_url . '";</script>');
}
$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);
$access_token_Clean = strtr ($access_token, array ('{"access_token":"' => '', '","token_type":"bearer"}' => ''));
$post_url = "https://graph.facebook.com/".$group_id."/photos?access_token=".$access_token_Clean;
echo '<form enctype="multipart/form-data" action=" '.$post_url.' "
method="POST">';
echo 'Please choose a file:';
echo '<input name="file" type="file" accept="image/*">';
echo '<input type="submit" value="Upload" />';
echo '</form>';
echo '</body></html>';