2010-06-22 9 views
7

Eventuali duplicati:
Add picture at facebook event with Graph APIAllega immagine da evento Facebook (php sdk, riposo o grafico api)

Ho cercato per poche ore buone ora per creare un evento attraverso l'API di Facebook con un'immagine. Finora sono stato in grado di creare eventi tramite le API Graph e Rest senza immagini, ma non sono stato in grado di allegare alcuna immagine.

Credo che l'API REST sia l'unica API che supporta il collegamento delle immagini, ma la documentazione è piuttosto scarsa e il codice o il codice php-sdk non sono di grande aiuto.

Il mio ultimo tentativo è finito a: http://promos.uk.glam.com/splash_test/example.php

Con il codice: http://pastebin.com/8JC8RAck (si noti la "richiedono facebook.php" è il php-sdk - http://github.com/facebook/php-sdk/)

nota linea 93 ("if ($ uid) {"), questo dovrebbe essere" if ($ me) {", che funzionava da un'ora o giù di lì, e poi ha smesso di funzionare (nessuna modifica al codice che popola $ me), strano.

Quindi, il codice di creazione dell'evento è le righe 96-99 e come è ora crea un evento senza un'immagine, ma non appena inserisco il codice commentato (riga 98) non riesce a fare nulla .

Qualcuno sa come creare eventi su Facebook attraverso l'API con le immagini? Se è così, per favore aiutami qui! Non ho problemi a scartare tutto questo codice se c'è un'altra soluzione, anche se devo usare PHP o Javascript.

Grazie a tutti

risposta

10

Grazie a tutti per le vostre risposte, ho deciso di rivisitare questo per vedere se l'API funziona correttamente ora. È! Il caricamento delle immagini con l'API Graph ora funziona.Grazie a Stan James per aver portato la mia attenzione su questo e dare il codice per pubblicare le foto, che ho adattato per gli eventi:

Setup:

//Setup the Facebook object allowing file upload 
$facebook = new Facebook(array(
    'appId' => 'xxxxxxxxxxxxxxxxxxxx', 
    'secret' => 'xxxxxxxxxxxxxxxxxxxx', 
    'cookie' => true, 
    'fileUpload' => true 
)); 

messaggio:

//Path to photo (only tested with relative path to same directory) 
$file = "end300.jpg"; 
//The event information array (timestamps are "Facebook time"...) 
$event_info = array(
    "privacy_type" => "SECRET", 
    "name" => "Event Title", 
    "host" => "Me", 
    "start_time" => 1290790800, 
    "end_time" => 1290799800, 
    "location" => "London", 
    "description" => "Event Description" 
); 
//The key part - The path to the file with the CURL syntax 
$event_info[basename($file)] = '@' . realpath($file); 
//Make the call and get back the event ID 
$result = $facebook->api('me/events','post',$event_info); 

ho messo tutto il codice su pastebin (http://pastebin.com/iV0JL2mL), è un po 'incasinato dal mio debugging e mi arrabbio con Facebook mesi fa! Ma funziona.

0

È possibile inviare le immagini a Facebook Like:

// variables required in this example: 
$img_path = "/home/www/test.png"; // image path 
$img_caption = "testing"; // caption 
$album_id = "12345678910"; // album id 
$facebook_uid = "555555555"; // facebook user id 
$facebok_user_access_token = "ajsdhflhasdf|sjdhflkasdf."; // facebook user token 

//upload photo 
$args = array(
    'aid'  => $album_id,  // album id, possibly event id? 
    'caption' => $img_caption, // caption for image 
    'uid'  => $facebook_uid, // facebook user id of the poster 
    'format' => 'json' 
    ); 
$args[basename($img_path)] = '@' . realpath($img_path); 
$ch = curl_init(); 
$url = "https://api.facebook.com/method/photos.upload?access_token={$facebook_user_access_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); 
$upload_result = curl_exec($ch); 

Questo è come è possibile utilizzare l'API per caricare le foto su album Facebook utilizzando PHP. Non esattamente sicuro che funzioni anche per gli eventi. Vorrei testarlo ma non riesco ad accedere a Facebook dal lavoro.

Spero che questo sia un buon inizio per voi.

2

Questo sembra funzionare

$file = "pj100.jpg"; 
$args = array(
    'access_token' => 'your access token', 
    'name' => 'Event name', 
    'description' => 'The Description ', 
    'start_time' => '2012-09-01T12:00:00+0000', 
    '@file.jpg' => '@' . realpath($file)); 
$target_url = "https://graph.facebook.com/me/events"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $target_url); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $args); 
$result = curl_exec($ch); 
curl_close($ch); 

echo "Event ID= " . $result; 
1

Il seguente codice funziona per me, utilizzando il PHP SDK.

$facebook->setFileUploadSupport(true); 
$attachment = array(
    'message' => $caption, 
);  
$attachment[basename($file_path)] = '@' . realpath($file_path); 
$result = $facebook->api('me/photos','post',$attachment); 

di farlo con cruda curl, vedere this answer.

Problemi correlati