我正在尝试制作一个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的解决方案,请分享
-Cory
稍微偏离主题,为什么要使用JavaScript而不是PHP进行重定向?
标头('位置:'.$dialogue_url);
试试这个
如果你正在提交表格,你可以这样做。
$sourceFile = $_FILES[$fileElementName];
$postdata = http_build_query(array('source' => '@'.$sourceFile['tmp_name']));
如果你只想测试
'source'=>'@'$imgLocalPath;