2013-05-08 133 views
0


我正在嘗試使用PHP創建Facebook事件。我有的最後一個問題是個人資料圖片。

我的問題是:
我可以使用外部圖片url的事件資料圖片?
如果是,比如何?來自外部URL的Facebook事件個人資料圖片

+0

這很奇怪,因爲在事件創建過程中你可以使用參數「圖片 - 事件圖片的URL」 – 2013-05-08 21:19:37

+0

哦......對不起..我以爲你是說你想要在外部託管圖片... – Lix 2013-05-08 21:22:02

回答

0

所以來自Lix的代碼只是從一部分開始。但是這是一個完整的工作代碼。

$externalImage = 'External link to image'; 
$tempImagePath = 'Local link to save image'; 
$user = 123456789; // USER ID 
// save image 
file_put_contents($tempImagePath, file_get_contents($externalImage)); 
// Create data for new event 
$data = array(
    'name'   => 'Event title', 
    'description' => 'Event description', 
    'owner'  => $user, // user as owner of this event 
    'location'  => 'Location', 
    'start_time' => '2013-05-08T11:00:00-0700', 
    'end_time'  => '2013-05-09T19:00:00-0700', 
    '@file.jpg' => '@'.realpath($tempImagePath), 
    'privacy_type' => 'OPEN' 
); 
// Create event 
$eventID = $facebook->api('/'.$account.'/events', 'post', $data); 

如果您有任何問題,請寫信給我。

2

您將無法真正使用該URL作爲個人資料圖片發送,但如果您首先將其下載到服務器上,則可以使用該URL。 file_get_contents()file_put_contents()的簡單組合可以複製圖像。

$externalImage = 'http://lorempixel.com/400/200/'; 
$tempImagePath = 'tmp/temp_image_path.jpg'; 
// save remote file to the server to $tempImagePath 
file_put_contents($tempImagePath, file_get_contents($externalImage)); 
// upload the image to the event 
$facebook->api("/EVENT_ID/picture", "POST", 
    array('source' => '@'. realpath($tempImagePath)) 
); 
// remove temp image 
unlink($tempImagePath); 
+0

它不工作。錯誤:$ facebook-> api中的數組到字符串的轉換請致電 – 2013-05-09 23:48:21

+0

其中一個參數提供的是一個數組,它應該是一個字符串。看看你指定的參數... – Lix 2013-05-10 06:59:50

相關問題