簡體   English   中英

使用API​​將照片從硬盤上傳到Facebook

[英]Uploading Photos from Hard Drive to Facebook using the API

想知道是否有人可以幫助我。 我一直在尋找有關如何使用API​​將照片發布到Facebook的幫助的幾天。 我遇到了以下腳本,該腳本似乎適用於所有人,但是我不確定如何將其連接到用戶可以從其硬盤中選擇照片並上傳的表單。 誰能指出我正確的方向?

PHP代碼:

$token = $session['access_token'];
$file= 'photo.jpg';
$args = array(
'message' => 'Photo from application',
);
$args[basename($file)] = '@' . realpath($file);

$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos?access_token='.$token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);

表單代碼:

<form action="<?=$PHP_SELF;?>" enctype="multipart/form-data" method="POST"> 
 <input name="MAX_FILE_SIZE" type="hidden" value="10000000" /> 
 <input id="file" name="file" type="file" /> 
 <input name="submit" type="submit" value="Upload" />
</form>

克拉克

php腳本在$ _FILES變量中接收文件及其詳細信息。

例如 如果要上傳文件名Image1.jpg,則$ _FILES數組將具有以下值

array(1){[“ file”] => array(5){[“ name”] =>字符串(21)“ Image1.jpg” [“ type”] =>字符串(10)“ image / jpeg” [ “ tmp_name”] =>字符串(23)“ C:\\ wamp \\ tmp \\ phpD1DF.tmp [” error“] => int(0)[” size“] => int(355315)}}

在這里, 名稱=實際文件名類型=文件類型tmp_name =服務器上文件上傳的臨時位置的路徑大小=文件大小

要將文件上傳到facebook,您應該對“ name”“ tmp_name”感興趣的值。

因此,您應發送至Facebook進行照片上傳的參數應如下所示:

$ args = array('message'=>'來自應用程序的照片',);

$ args [$ _ FILES ['file'] ['name']] ='@'。 $ _FILES ['file'] ['tmp_name'];

我認為這應該為您工作。

順便說一句,我簽出了用於上傳照片的facebook文檔@ http://developers.facebook.com/docs/reference/api/photo他們說文件名應該在參數“源”中傳遞,因此如果上述參數不存在為您工作,您可以嘗試

$ args = array('message'=>'來自應用程序的照片','source'=>'@'。$ _FILES ['file'] ['tmp_name']);

試試看:)希望這會有所幫助。

暫無
暫無

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

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