2013-03-30 142 views
1

提供在網站上選擇點擊並上傳圖片在Facebook上的路徑: 搜索Facebook的PHP SDK上傳圖片 - 圖片

$pic = $_GET['PhotoID']; //example: http//www.mysite.com/content/2013/03/image.jpg 
copy($pic, 'tmp/file.jpg'); 
$args['image'] = '@' . realpath('tmp/file.jpg'); 
$publish = $facebook->api('/me/photos', 'post', $args); 
unlink('tmp/file.jpg'); 

此代碼工作正常後,得到這個代碼。 但將圖像複製到tmp需要一些時間我想加快過程。 (上傳我的網站只是沒有對外形象圖片)

我如何使用這個代碼,無需複製到溫度:

$pic = $_GET['PhotoID']; //example: http://www.mysite.com/content/2013/03/image.jpg 
    $args['image'] = '@' . realpath('$pic'); 
    $publish = $facebook->api('/me/photos', 'post', $args); 

不知道的使用「@」 &真實路徑 我可以使用完整的圖像網址不使用真實路徑:

`$args['image'] = $pic; 
     $publish = $facebook->api('/me/photos', 'post', $args);` 

&什麼是顯示錯誤消息,如果用戶DNT批准的應用程序的最佳途徑。 或類似致命錯誤錯誤:未捕獲OAuthException發生

+0

結帳http://stackoverflow.com/a/14726580/718224&http://stackoverflow.com/a/14937938/718224 –

+0

@AdvaitAmin對不起它不涉及疑問句。我想要圖像的絕對路徑示例代碼(完整的圖像url) – Vehlad

+0

您的問題是複製圖像到tmp需要一些時間,你想加快過程意味着上傳過程需要太多的時間... –

回答

0

我已經做了我的應用程序一樣,JST去用這個.. 確保您有權限publish_stream

$attachment = array(
       'message' => 'Message', 
       'name' =>'your app name', 
       'caption' => "caption under the image", 
       'link' => 'your link', 
       'description' => 'description regarding the image', 
       'picture' => 'path of the picture(doesnt work for the local path, should be server path)', 
       'method'=>'stream.publish', 
       'actions' => array(
           array(
            'name' => 'App name', 
            'link' => 'your app link' 
           ) 
          ) 
       ); 

然後

$result = $facebook->api('/'.$uid.'/feed/','post',$attachment); 

這裏$ uid是Facebook的,您可以從Facebook的配置文件中獲取的用戶ID

$facebook = new Facebook('configure your facebook config file here');  
$my_details = $facebook->api('/me'); 
$uid = $my_details['id']; // id of the user 
2

您無需複製圖片至/tmp。您可以通過在參數中提供圖像url本身直接上傳圖像。下面的代碼應該工作:

$picUrl = 'http//www.mysite.com/content/2013/03/image.jpg'; 
$photoId = $facebook->api("me/photos","POST",array('url'=>$picUrl,'message'=>"status message")