0

我正在尝试制作一个 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 的解决方案,请分享

-科里

4

2 回答 2

0

有点跑题了,为什么你使用 JavaScript 来重定向,而不是 PHP?

header('位置:' . $dialogue_url );

于 2012-04-06T17:20:55.943 回答
0

尝试这个

如果您正在提交表单,您可以这样做。

$sourceFile = $_FILES[$fileElementName];

$postdata = http_build_query(array('source' => '@'.$sourceFile['tmp_name']));

如果你只是想测试

'来源' => '@'.$imgLocalPath;

于 2012-04-09T11:08:32.567 回答