I have no idea why the getRequestForNextPage(); doesnt work.
I use it like this:
$photoRequest = new FacebookRequest( $session, 'GET', '/'.$albumId.'?fields=photos.limit(30){picture,created_time,id,updated_time,width,height,from,link}' );
do{
pretty_print($photoRequest);
$response = $photoRequest->execute();
$graphObject = $response->getGraphObject()->asArray();
foreach($graphObject['photos']->data as $index => $photo){
// work on photos
}
}while ($photoRequest = $response->getRequestForNextPage());
I know for certain theres more then 30 pictures on 2 of the albums i go through, yet it still shows only the first 30.
When I var_dump $photoRequest = $response->getRequestForNextPage() it always returns null..
Is this the way to use this method?
Related
I would like to ask a facebook timeline with php sdk.
$this->FaceBookApp = new Facebook\Facebook(array(
"app_id" => $this->appId,
"app_secret" => $this->appSecret,
"default_graph_version" => $this->defaultGraphVersion
));
$this->FaceBookApp->setDefaultAccessToken($this->appId .'|'. $this->appSecret);
$Fields = "fields=type,message,source,picture,created_time,name,link,description,is_published";
$response = $this->FaceBookApp->get('/'.$this->userId.'/posts?limit=100&'.$Fields, $this->appId .'|'. $this->appSecret);
$list = $response->getDecodedBody();
$this->workingList = $list["data"];
count($this->workingList) = 36;
regardless of the value of the limit, but the Graph API Explorer returns 100 results.
and the filter does not work.
And:
$feedEdge = $response->getGraphEdge();
$nextFeed = $this->FaceBookApp->next($feedEdge);
$nextFeed = NULL !!
how can i get the last 100 post or how can i filter list?
thanx
I'm working on PHP project. I have to get id, fullname, firstname, gender and email of the user. I got id of the user. So, It is clear that there is no any problem in PHP facebook-sdk or Facebook library. But I can not get other fields. So, ther is something is wrong in my code. But I can't find that wrong code. If anyone know answer then please explain or suggest me link from where I can understand from beginning. Thank You. Here is my code. Here is my code.
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
echo $fbid; //working as I'm getting facebook ID
$filenameIn = 'https://graph.facebook.com/' . $fbid . '/fields=gender';
$gender = file_get_contents($filenameIn);
echo $gender; //I can not get this.
CBroe is right. I have made that mistake. As I changed my code as CBroe has suggested, I got problem Solved. Here is correct code.
$request = new FacebookRequest($session, 'GET', '/me?fields=id,gender');
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
$fbgender = $graphObject->getProperty('gender'); // To Get Facebook gender
echo $fbid; //working as I'm getting facebook ID
echo $fbgender;//working as I'm getting facebook gender
I am new in Facebook APPS and i want to get all photos that the user has in his account after login
i made the login and the permission well
$request = new FacebookRequest( $session, 'GET', '/me/photos' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject()->asArray();
when i print the array using print_r( $graphObject, 1 ),it gives me long array i got confused
i want fetch the photos only to be able to put it into loop
think like this echo $graphObject['data']['0']['source'];
Once you get the result from the API call, you can output the data to your page as:
foreach ( $graphObject['data'] as $photo ) {
echo '<img src="{$photo->images[0]->source}" />';
}
Im really struggling w/ the OAuth for Khan Academy. This is for my class website (Im a teacher) and I want to pull in user data on particular students. If I could do the OAUTH I would be fine. Im using PHP.
There seems to be many librarys out there, I have been playing w/ Google Oauth (located here http://code.google.com/p/oauth-php/source/browse/trunk/example/client/twolegged.php)
I can formulate the token request fine, although when I call it in the script, it seems like it tries to redirect to another page and gets blocked there.
http://myonlinegrades.com/prealg/khan/oauth-php/example/client/twoleggedtest.php
Im really struggling - Id love any help you might offer.
Code below:
<?php
include_once "../../library/OAuthStore.php";
include_once "../../library/OAuthRequester.php";
// Test of the OAuthStore2Leg
// uses http://term.ie/oauth/example/
$key = '*********';//'<your app's API key>';
$secret = '***********';//'<your app's secret>';
$callBack = "http://myonlinegrades.com/prealg/test2.php5";
$url = 'http://www.khanacademy.org/api/auth/request_token';
$options = array('consumer_key' => $key, 'consumer_secret' => $secret);
OAuthStore::instance("2Leg", $options);
$method = "GET";
//$params = null;
$params = array(oauth_consumer_key => $key,oauth_callback=>$callBack);
try
{
// Obtain a request object for the request we want to make
$request = new OAuthRequester($url, $method, $params);
// Sign the request, perform a curl request and return the results,
// throws OAuthException2 exception on an error
// $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string)
$result = $request->doRequest();
$response = $result['body'];
if ($response != 'oauth_token=requestkey&oauth_token_secret=requestsecret')
{
echo 'Error! $response ' . $response;
}
else
{
}
var_dump($response);
}
catch(OAuthException2 $e)
{
echo "Exception" . $e->getMessage();
}
?>
Not sure this is what you're looking for, but I put together a simple example of doing oAuth with Khan Academy using the Temboo SDK: take a look at https://github.com/matthewflaming/temboo-experiments/tree/master/KhanAcademyOauth
(Full disclosure: I work at Temboo)
Can anyone shed some light on my problem?
<?php
$config = array();
$config['appId'] = "foo";
$config['secret'] = "bar";
$config['cookie'] = true;
$config['fileUpload'] = true;
$facebook = new Facebook($config);
$eventParams = array(
"privacy_type" => $this->request->data['Event']['privacy'],
"name" => $this->request->data['Event']['event'],
"description" => $this->request->data['Event']['details'],
"start_time" => $this->request->data['Event']['when'],
"country" => "NZ"
);
//around 300x300 pixels
//I have set the permissions to Everyone
$imgpath = "C:\\Yes\\Windows\\Path\\Photo_for_the_event_app.jpg";
$eventParams["#file.jpg"] = "#".$imgpath;
$fbEvent = $facebook->api("me/events", "POST", $eventParams);
var_dump($fbEvent); //I get the event id
I also have this in my "scope" when the user is asked to Allow the app to post on his behalf: user_about_me,email,publish_stream,create_event,photo_upload
This works. It creates the event with all the details I have specified. EXCEPT for the event image.
I have been to most of Stackoverflow posts related to my problem but all of them are not working for me. (EG: https://stackoverflow.com/a/4245260/66767)
I also do not get any error.
Any ideas?
THanks!
Yes, the idea is that Facebook has bug.
I have problems with event picture as well. The topic in tracker and this is my post on stackOverflow
Btw, you can try this code after creating the event ->
public function uploadFacebookEventPicture($fullPath, $eventId) {
$mainImage = '#' . $fullPath;
$imgData = array(
'picture' => $mainImage
);
try {
$data = $this->facebook->api('/'.$eventId, 'post', $imgData);
return $data;
} catch (FacebookApiException $e) {
error_log('Failed to attach picture to event. Exception: ' . $e->getMessage());
}
return null;
}
Maybe it will work for you, for me it stopped to work since Facebook issue was discovered.