我正在尝试制作一个PHP脚本,它将托管照片发布到用户的个人资料中,而不使用PHP SDK。这就是我现在所拥有的:使用Graph API和PHP发布托管照片
<?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的一个解决方案,请分享
-Cory
...同样的原因我没有使用PHP SDK。我收到一个错误,可能会有一个简单的解决办法,但我真的不知道我在做什么。 – 2012-04-07 04:36:48
嘿,这就是我们开始的地方:-)你会收到什么错误?它是否已经发送了标题? – Azirius 2012-04-07 12:11:13
是的,有会话cookie和标题......你知道,很多人似乎都有这个 – 2012-04-07 18:50:45