how to get all group images in facebook using FACEBOOK API - php

i'm trying to get all the images from a facebook group using facebook API
i have a problem i can't get all the photos using
$facebook->api_client->call_method('Photos.get', array('subj_id' => $uid));
http://wiki.developers.facebook.com/index.php/Photos.get
what i'm using now is the method
$albums = $facebook->api_client->photos_getAlbums($uid, NULL);
http://wiki.developers.facebook.com/index.php/Photos.getAlbums
and then loop for ever album on
$facebook->api_client->call_method('Photos.get', array('subj_id' => $uid));
then i add every new array results to my big array
$big_array = array_merge($big_array,$result_array_from_that_call);
2 problems occurs here :
1- sometimes this calls fails - i think because of too many calls per second -
2- the request takes a v.long time to process
is there a better way to do that?
Thanks guys
Cheers
EDIT :: i tried to get all the images using
$facebook->api_client->call_method('Photos.get', array('subj_id' => $uid));
and using $uid as the group ID but that's doesn't work " don't know why maybe because all the images is listed in groups "

the best solution was to output the album and then the user clicks on an album and check the images inside it

Related

Twilio Paging Information

Im using the Twilio PHP Sdk.
$AccountSid = env('TWILIO_SID');
$AuthToken = env('TWILIO_TOKEN');
$this->twi = new TwilioClient($AccountSid, $AuthToken );
And Im retrieving call logs like so.
$calls = $this->twi->calls->read(["to" => "+".$number->number], 15);
This is fine, and is returning 15 records of the latest calls.
But how do I access paging information such as how many total records are available, and how many pages are available to view. So that I can display some sort of pagination on my page??
I tried just accessing the Calls.json object, via CURL without using the SDK, like this...
$url = "https://api.twilio.com/2010-04-01/Accounts/".$AccountSid."/Calls.json?PageSize=15";
And that gave me a nice JSON object, with some paging info such as next_page_uri and previous_page_uri.
[previous_page_uri] =>/2010-04-01/Accounts/AC##########/Calls.json?PageSize=15&Page=0
[page_size] => 15
[start] => 0
[next_page_uri] => /2010-04-01/Accounts/AC##########/Calls.jsonPageSize=15&Page=1&PageToken=PACA27b63143f18c458f2abd35ef90753e5a
[page] => 0
But still, no totals such as total records, or total pages in the query??? So I cant display a nice bar of pagination at the bottom of my table, to show how many actual pages there are?
This seems dumb.
Is there no way to get this information?? Without actually storing the calls individually in my own database, so I can provide this manually?
Also.....one other question (assuming I cant retrieve that information)
I still want to be able to navigate from page to page, via the SDK instead of CURL requests. So....how do I pass the page number to the Twilio SDK? Ive tried...
$calls = $this->twi->calls->read(["To" => "+".$number->number,"Page"=>22], 15);
But it still just returns the first page. So how do I paginate these records via the SDK??
I am not sure about total pages, but for pagination i have used TWILIO PHP SDK's function,
Here how it will work,
//this will fetch first 10 calls
$calls = $twilio->calls->page([], 10, \Twilio\Values::NONE, 0);
//then you just need to call 2 methods for next and previous page
$nextPageData = $calls->nextPage(); //this will return data of next page
$previousPageData = $calls->previousPage(); // this will return data of previous page
// to check if current page has valid data
if(!$nextPageData->valid()){
//Invalid page
}
This is what i used for pagination on my project.

Updating Soundcloud Playlist via Soundcloud Wrapper

In reference to this post How to create SoundCloud playlist using PHP wrapper
I am using the Njasm/Soundcloud Wrapper in PHP to manage our track uploads and playlist creation. According the the post referenced above I need to rebuild the entire track list whenever I want to update the playlist.
Is there a way to update a current playlist so that we can simply add a track to a playlist? Or do we have to rebuild the list of track id's each time?
First of all, thank you for using my library.
In response to your question, and to the best of my knowledge, that's a limitation of the Soundcloud API itself. You'll have to recreate the playlists every time you want to update it.
Reference: https://developers.soundcloud.com/docs/api/guide#creating-sets
Hope it helps.
PS - If you find a way to add/remove single track to/from an existing playlist, please be my guest and share the trick or send pull request in github. I'll be more then glad to merge it. :)
Not a super sexy solution, but I just rebuild the list like this.
$currentPlaylist = 12312312312; // Id of target playlist
$response = $facade->get(
'/playlists/'.$currentPlaylist)->request();
$set = $response->bodyArray();
$trackList = array();
$trackNew = array();
foreach ($set['tracks'] as $episode) {
$trackNew = array("id" => $episode["id"]);
$trackList[] = $trackNew;
}
$tracks = array(
"playlist" => array(
"tracks" => $trackList)
);
$response = $facade->put(
'/playlists/' . $response->bodyObject()->id,
$tracks
)->request();

Instagram API to fetch all photo in php

i'm using this api:
public function getUserMedia($id = 'self', $limit = 0) {
return $this->_makeCall('users/'.$id.'/media/recent', true, array('count' => $limit));
}
to fetch the photo of a user logged in my site using php
it works, and all other api works.
the problem is that i want to retrieve ALL the photo of a user (such as printstagr.am).
i've searched in the api but without success: it seems that you can take the recents or the populars, but the site mentioned above takes all. any idea?
thanks!
Not sure what the max count is (saw someone mention 20 was the max on another question, but can't find any limit in the docs from a quick scan), but essentially what you have to do is request as many as possible, then follow the pagination links to collect more.
So from the api docs they provide this:
{
...
"pagination": {
"next_url": "https://api.instagram.com/v1/tags/puppy/media/recent?access_token=fb2e77d.47a0479900504cb3ab4a1f626d174d2d&max_id=13872296",
"next_max_id": "13872296"
}
}
Your application needs to store the objects from the request (i.e. an array), then fire a new request to the "next_url", put those objects into the same store (i.e. array), then follow the link again, until you reach the end or until you get enough to satisfy your needs.

Multi-photo upload to album and wall story

I'm confident about posting multiple photos to a fan page album through a common batch request with PHP, and I also know how to use che "no_story" command to hide the wall posts showing each image just uploaded. What I need to know is if it's possible to show an unique wall post on the fan page showing the whole upload, like the standard Facebook behavior when you upload more pictures using the web interface, and not one post for each photos.
This is the closest I have got:
$attachment = array
(
'access_token'=>$fanPageAccessToken,
'object_id' => $AlbumId,
'message' => $AlbumDesc,
'link' =>$AlbumLink
);
$result = $facebook->api($fanPageId.'/links/','post',$attachment);
}
I get the variables by querying the albums associated with the fanpage:
$fanPageAlbums = $facebook->api($fanPageId . '/albums/');
foreach ($this->fanPageAlbums['data'] as $fanPageAlbum) {
if ($albumId == $fanPageAlbum['id']) {
$albumLink = $fanPageAlbum['link'];
$albumDesc = $fanPageAlbum['description'];
break;
}
}
The key thing is your are posting to the links part of the graph, not the feed.
This works in that it will produce one big picture and three thumbs below it, as you would expect. However, it doesn't appear on the feeds of friends properly.
I've been struggling with this for ages, and the above is the closest I have got to mimicing exactly the facebook behavior. If you get any further please let me know!

Tagging photos on Facebook with Graph API / PHP SDK

The question is pretty much in the title, but to be more specific, I'm working on a facebook contest for a client in which people have to upload photos to take part in it after accepting rules and subscribing, etc.
After going down a long road full of deceptions
(here's what I tried that didn't work in the end:
uploading to the user's album then tagging the page: nope, can't tag a page
uploading to a public album in the page, like "fan photos", or wall photos? can't find anything AT ALL about a way to do this, though it would've been my preferred way.)
So, I ended up having an idea: I would do this in two steps. First, the user subsribes and uploads a photo to my PHP server. Then, another, different application with permissions on the account that has the page, would take control of it, upload all the photos at 5 minutes intervals (meaning, you subsribe, 5 minutes later, your photo's uploaded.)
So far, so good; I don't like the logic behind this, but it's the only way I found! So, I did the base, I'm able to post a photo with a caption as the page in a dedicated app album.
BUT! I can't tag anyone in those photos. Maybe you can't tag as a page, maybe you can't tag in page albums, maybe I don't have the permissions required (I have stream_publish, user_photos, friends_photos, offline_access, and I could add anything if I need to since it's a private-use app anyway). Oh and, the user I'm trying to tag is the admin for both the app and the page (and he likes the page). I don't know, but it's driving me crazy. I hate the official documentation, there's no example code, you have to figure out most of the things, go through trial and error or search on the web for people who did so and shared how to do things. Not nice when you have little time to complete a project for a client without busting the budget.
Anyway, here's my error I keep getting whenever I try to tag someone to a photo from any album:
OAuthException: (#322) Invalid photo tag subject
And here's the code I'm using to upload a photo from the server to facebook.
if ($user) {
try {
$page_info = $facebook->api("/$page_id?fields=access_token");
if( !empty($page_info['access_token']) ) {
// First method, at the same time as upload. Upload works but no tags
$args = array(
'access_token' => $page_info['access_token'],
'source' => '#' . realpath($FILE_PATH),
'message' => "test"
'tags' => array(
array(
'tag_uid'=> "MY_USER_ID",
'x' => 0,
'y' => 0
))
);
$post = $facebook->api("/$page_id/photos","post",$args);
$postID = $post['id'];
// Second method I'm trying. No tags.
$tag = $facebook->api("/$postID/tags/MY_USER_ID","post");
print_r($tag);
}
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
Any help would be appreciated. Thanks in advance!
EDIT :: Now I got it partly working using the second part in the code, but only if I remove the "access_token" parameter from the photo posting first. Basically, it only works if I upload it to a personal album. But that's as far as it gets from what I want. When I upload it to the album from the page, it says I asked for tag requests, but on my personal account which I tagged, I don't receive anything. Baaaah.
RE-EDIT :: After much tries, it seems I can't tag someone as a page or in a page album. I'll try to find an alternative, I guess.

Categories