簡體   English   中英

PHP SCRIPT問題,將上傳的圖像傳遞到facebook-> api函數

[英]PHP SCRIPT issue with passing the uploaded image to facebook->api function

如果我提供圖像的直接鏈接,則我有這段代碼,它的工作效果非常好。


僅有的一個問題,我無法將上傳的圖像傳遞給facebook-> api(無論其是否有效),並且以下內容始終會出現


echo'僅支持jpg,png和gif圖像類型!


我什至取消了對圖像類型的檢查,並嘗試從$ img = realpath($ _ FILES [“ pic”] [“ tmp_name”])獲取圖像。 但是$ img卻什么也沒有,並且默認在我的頁面上在Facebook上上傳一個空圖像請檢查我的以下代碼,並讓我知道我的代碼有什么問題,我應該怎么做才能上傳圖像

以下代碼的在線鏈接: http : //radiations3.com/facebook/1.php

 <?


require 'src/facebook.php';

$app_id = "364900470214655";
$app_secret = "xxxxxxxx";

$facebook = new Facebook(array(
 'appId' => $app_id,
 'secret' => $app_secret,
 'cookie' => true,
 'fileUpload' => true,
));

$user = $facebook->getUser();
//echo $user;

if(($facebook->getUser())==0)
{
 header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos,offline_access,manage_pages'))}");
 exit;
}
else {
$accounts_list = $facebook->api('/me/accounts');
echo "i am connected";
}
  $valid_files = array('image/jpeg', 'image/png', 'image/gif');


//to get the page access token to post as a page
foreach($accounts_list['data'] as $account){
      if($account['id'] == 194458563914948){      // my page id =123456789
        $access_token = $account['access_token'];
        echo "<p>Page Access Token: $access_token</p>";
        }
    }

//posting to the page wall

if (isset($_FILES) && !empty($_FILES))
{  
if( !in_array($_FILES['pic']['type'], $valid_files ) )
{
  echo 'Only jpg, png and gif image types are supported!';
 }
 else{
  #Upload photo here
  $img = realpath($_FILES["pic"]["tmp_name"]);
$attachment = array('message' => 'this is my message',
                'access_token'  => $access_token,
                'name' => 'This is my demo Facebook application!',
                'caption' => "Caption of the Post",
                'link' => 'example.org',
                'description' => 'this is a description',
                'picture' => '@' . $img,
                'actions' => array(array('name' => 'Get Search',
                                  'link' => 'http://www.google.com'))
                );
$status = $facebook->api('/194458563914948/feed', 'POST', $attachment);   // my page id =123456789
var_dump($status);
}
}
?>
<body>
 <!-- Form for uploading the photo -->
 <div class="main">
  <p>Select a photo to upload on Facebook Fan Page</p>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
  <p>Select the image: <input type="file" name="pic" /></p>
  <p><input class="post_but" type="submit" value="Upload to my album" /></p>
  </form>
 </div>
</body>

上傳后,我收到了以下回調

我是connectedarray(1){[“ id”] => string(31)“ 194458563914948_415487041812098”}

圖API資源管理器建議上傳成功

https://developers.facebook.com/tools/explorer?method=GET&path=194458563914948_415487041812098

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM