I'm using the following code to get a track list from SoundCloud. The issue is it only returns 200 tracks and not the entire list. Can someone please help.
$soundcloud_url = "http://api.soundcloud.com/users/{$userid}/tracks.json?client_id={$clientid}&limit=10000";
$tracks_json = file_get_contents($soundcloud_url); //get tracks
$tracks = json_decode($tracks_json); //convert tracks
That is the maximum value of collection items returned by the API, by default it is set to 50 but it can go up to 200.
You can pagine through collections of tracks, check the below code which uses linked_partitioning parameters that indicates the response include a next_href property that points the next collection:
# start paging through results, 100 at a time
tracks = client.get('/tracks', order='created_at', limit=page_size,
linked_partitioning=1)
for track in tracks:
print track.title
Check this for detailed info.
Related
I have a query that displays 250 events that my local clubs calendar has added to their calendar.
It currently only goes up until 2021 which is not what I want. How do I get it to show current dates, do I have to change a setting or am I supposed to use the next page token?
$json = file_get_contents('https://www.googleapis.com/calendar/v3/calendars/'.$calName.'/events?key='.$key.'');
// Converts it into a PHP object
$data = json_decode($json, JSON_OBJECT_AS_ARRAY);
$length = count($data['items']);
$i=0;
while ($length != $i){
print_r($data['items'][$i]['start']);
print_r("<br/>");
$i ++;
minimal output
According to the Google Calendar API documentation for the maxResults optional query parameter:
Maximum number of events returned on one result page. […] By default the value is 250 events. The page size can never be larger than 2500 events.
So by default, a single request is limited to 250 events but you can increase this to 2500. You may need to set up paging even if you set the maxResults to the maximum 2500.
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.
I'm having trouble using the API to view a segment. I'm using PHP. My code is as follows:
$url = "https://us7.api.mailchimp.com/export/1.0/list/?apikey=$api_key&id=$list_id&$segment";
$result = file_get_contents($url);
where $segment is an array used to generate the segment.
I can get the following version working...
$segment = "segment[match]=all"
"&segment[conditions][0][field]=LNAME".
"&segment[conditions][0][op]=like".
"&segment[conditions][0][value]=smith";
which generates a segment of all subscribers to my list with a last name containing "smith".
However, what I actually want to do is generate a segment based on people who've been sent any mailer in the last 7 days. I've created this manually to get the correct fields and generated the following array based on it:
$segment = "segment[match]=all".
"&segment[conditions][0][condition_type]=Aim".
"&segment[conditions][0][field]=aim".
"&segment[conditions][0][op]=sent".
"&segment[conditions][0][value]=last7day";
but it's giving me a 300 error. This isn't listed in MailChimp's current error glossary on the export api documentation, but according to a snapshot of the old error documentation means "Campaign doesn't exist" (https://web.archive.org/web/20130209144951/https://apidocs.mailchimp.com/api/1.3/exceptions.field.php) which is weird because I'm not referencing a campaign.
What am I doing wrong?
// , Click on playground and with your API key.
Generate some responses and look at the campaign id.
It's not the integer value you see when hovering over the campaign with id=, it's another value.
Look for the id that the API needs in the response.
This will fix your issue.
I'm trying to use the photos_getRecent function which, in the source file, is described as:
function photos_getRecent ($jump_to = NULL, $extras = NULL, $per_page = NULL, $page = NULL)
I'm trying to filter the results based on the owner, which (according to the documentation http://www.flickr.com/services/api/flickr.photos.getRecent.htm) is stored in the extras variable:
"A comma-delimited list of extra information to fetch for each returned record. Currently supported fields are: description, license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_q, url_m, url_n, url_z, url_c, url_l, url_o"
So I've tried setting the extras variable to a whole lot of stuff:
photos_getRecent(NULL,"owner_name=john citizen",20,NULL);
photos_getRecent(NULL,"owner_name=john_citizen",20,NULL);
photos_getRecent(NULL,"owner_name:john citizen",20,NULL);
photos_getRecent(NULL,"owner_name:john_citizen",20,NULL);
photos_getRecent(NULL,"owner_name,john citizen",20,NULL);
photos_getRecent(NULL,"owner_name,john_citizen",20,NULL);
photos_getRecent(NULL,"owner_name=10000000#N00",20,NULL);
photos_getRecent(NULL,"owner_name:10000000#N00",20,NULL);
photos_getRecent(NULL,"owner_name,10000000#N00",20,NULL);
but none of them seem to do the trick. Every time it just gets a bunch of random photos with random owners.
Unfortunately the documentation isn't specific at all, and I can't find any examples online using this stuff.
How can I properly format the variable $extras to have it get me the photos only for that owner?
The extras parameter is used in the Flickr search to denote extra fields that you want returned by the API, not fields to search by.
To get photos by a specific owner, you'll want to use photos_search function in the phpFlickr library and pass the argument user_id for your photo owner. The default sort order is date-posted-desc which should get what you are after. For example:
photos_search (array('user_id' => '10000000#N00'));
Check out Flickr's API doco for the search function for more details.
I am using the Google Analytics PHP class to get data from Google Analytics.
http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation
I would like to get a report of "Bounce Rate" For "Top Contnet".
The thing is I am not familiar with the terminology.
When I am trying to get a "content" report or "topcontent" or "top_content" it says that there in no such metric. I simply don't know the right expressions.
Does anyone know where can I find a list of all expressions? metrics & dimensions?
Thanks.
Top content isn't a metric, it's just a list of the pages on your site with the highest number of page views.
The metric you're looking for is 'entranceBounceRate' and the dimension is 'pagePath'. You want to get the bounce rate for the top X most visited pages on your site, so you'll want to limit your results and sort the results by '-pageviews' (pageviews descending).
If you want to get the bounce rate for the top 10 most viewed pages on your site, your query should look like this:
$ga = new gapi('email#yourdomain.com','password');
$ga->requestReportData(145141242,array('pagePath'),array('entranceBounceRate','pageviews'),array('-visits'),null,null,null,10);
The Google Analytics Export API has a data feed query explorer that should help you out considerably when using GAPI:
http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html
Also, here's a list of all available dimensions and metrics you can pull from the API:
http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html
Definitely read over the GAPI documentation:
http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation
If you would like to get the global Bounce Rate for the last 30days (by default), here is how. Very simple once you know it.
//Check Bounce Rate for the last 30 days
$ga = new gapi(ga_email, ga_password);
$ga->requestReportData(145141242, NULL ,array('bounces', 'visits'));
$data = round(($ga->getBounces() / $ga->getVisits()) * 100) . "%";
Note that the GAPI has a bug, they mention the dimension parameter is optional (2nd parameter) but it's not. You have to open the gapi.class.php file and patch line 128 with this:
//Patch bug to make 2nd parameter optional
if( !empty($dimensions) ) {
$parameters['dimensions'] = 'ga:'.$dimensions;
} else {
$parameters['dimensions'] = '';
}