我正在尝试制作一个 PHP 脚本,该脚本将在不使用 PHP SDK 的情况下将托管照片发布到用户的个人资料中。这就是我现在所拥有的:
<?php
$app_id = "[My App ID]";
$app_secret = "[My App Secret]";
$post_login_url = "[current page]";
$code = $_REQUEST["code"];
//Obtain the access_token with publish_stream permission
if(empty($code)){
$dialog_url= "http://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode( $post_login_url)
. "&scope=publish_stream";
echo("<script>top.location.href='" . $dialog_url
. "'</script>");
}
else {
$token_url="https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode( $post_login_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// This would probably be where my problem is
$graph_url= "https://graph.facebook.com/me/photos?"
. "access_token=" .$access_token;
$postdata = http_build_query(
array(
'source' => $imageurl, //this variable has been properly defined
'message' => $image_description //this, too, has been defined
)
);
$opts = array('http' =>
array(
'method'=> 'POST',
'header'=>
'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
}
?>
运行时,会创建一个具有应用名称的新专辑,但不会上传文件。有什么办法可以使这项工作?如果有人知道 PHP 甚至 javascript 的解决方案,请分享
-科里