Twilio PHP : getIterator - twilio

I am trying to retrieve call logs from twilio using twilio-php library. With the following code, I expect twilio to return last 10 records but it returns everything. I tried finding docs for this, but couldn't find it.
foreach ($client->account->calls->getIterator(0, 10, array(
'To' => $_GET['callerid']
)) as $call){
}
Can anyone please help me how I can use the above code to display logs page wise. Like for 1st page it returns recent 1-10 logs. For second page 11-20 and so one.
Appreciate your help.

Twilio developer evangelist here.
Unfortunately there seems to be a known issue with the getIterator method that will make it return all the results regardless of the number of items you declare.
What it does however is iterate through all the results and make multiple requests to the API for each of the pages as described here.
What you can do however is use the getPage method, that will take a page number and number of records as such:
$callLog = $client->account->calls->getPage(0, 10, array(
'StartTime>' => '2015-04-01',
'StartTime<' => '2015-05-01'
));
var_dump($callLog->num_pages);
foreach ($callLog->getItems() as $call) {
echo "From: {$call->from}\nTo: {$call->to}\nSid: {$call->sid}\n\n";
}
All you need to do then is change the page number (first argument on getPage()).
Hope this helps you.

Related

TWILIO-API: List recording within a data range

this example provided on Twilio website is not working:
$records = $client->recordings->read(0, 10, array(
"datecreatedBefore" => "2016-12-04",
"datecreatedAfter" => "2016-12-01"
));
It still shows also recordings outside this range. Any idea how to filter by date?
Thanks!
Twilio developer evangelist here.
It looks like there maybe a mistake in translating from the v4 Twilio PHP library to the v5 library. Previously, the getIterator method took a page and page size argument before the remaining options for filtering.
$recordings = $client->account->recordings->getIterator(0, 50, array(
"DateCreated<" => "2016-10-15",
"DateCreated>" => "2016-10-12"
))
With the v5 library, read takes the array of options first, followed by a limit and then page size. So, to use the iterator with a limit of 10 you need to call it like this:
$recordings = $client->recordings->read(array(
"datecreatedBefore" => "2016-12-04",
"datecreatedAfter" => "2016-12-01"
), 10, 10);
Let me know if this helps at all.

how to Add titles and descriptions to videos on YouTube in other languages using api v3?

I had studied hardly the documentation on https://developers.google.com/youtube/v3/revision_history#november-19-2015 about how to Set localized titles and descriptions.
But when you try it, it seems impossible, even if you use the "app" of the api on https://developers.google.com/youtube/v3/docs/videos/update#prubalo you always get the same error with the parameter part. I set that parameter with the value "snippet", like you have to do. But it doesn't work, I tried with the rest of values or possible combinations and..it doesn't work.
Can someone give me an example of the code (i prefer python) or the request http ??
Please be sure you code o request http really works...even i found any mistakes on the examples on the documentation like 5 opening parenthesis and 4 closing parenthesis...
Following is an PHP code example. The concept is same, hope you can do it in the Phython.
Please make sure you set the default language of the video (snippet.defaultLanguage) before adding localisations.
// Call the API's videos.list method to retrieve the video resource.
// Part should be 'localizations' not 'snippet' because you are updating the localisation
$listResponse = $youtube->videos->listVideos('localizations', array('id' => 'YOUR_VIDEO_ID'));
// Since the request specified a video ID, the response only contains one video resource.
$video = $listResponse[0];
// Set the localisations array for the video localisation
// You can retrieve the language list from following API - https://developers.google.com/youtube/v3/docs/i18nLanguages/list
$video['localizations'] = array(
'ta' => array(
'title' => 'TITLE_IN_GIVEN_LANG',
'description' => 'DESC_IN_GIVEN_LANG'));
// Update the video resource by calling the videos.update() method.
$updateResponse = $youtube->videos->update('localizations', $video);
Update - Example of updating localisation of video using google developer console

listSearch by videoCategoryId falls with error , until today it worked

Today I've encountered error with php-code, it worked for six months, and now it falls
$listResponse = $youtube->search->listSearch(
'id,snippet',
array(
'channelId' => 'UCeP5_pUXbKpMlR-_mVQTCSg',
'maxResults'=>3,
'order'=>'date',
'type'=>'video',
'videoCategoryId'=>'UCeP5_pUXbKpMlR-_mVQTCSg.jNQXAC9IVRw'
)
);
I've checked it with "youtube try'it" service and get error http://take.ms/WXSBj
Please!! Help me! Need Assistance!)
UPDATE 1: This is API BUG: do you know how to get category videos via another method ?
and problem is only in parameter videoCategoryId
The reason is probably in video category id values,
I've get that values via method $youtube->channelSections->listChannelSections
It is popularVideos.
So, my code works without specifying them thanks to "order = date" parameter.

firefox addon webrequest.addListener misbehaving

I want to examine http requests in an extension for firefox. To begin figuring out how to do what I want to do I figured I'd just log everything and see what comes up:
webRequest.onResponseStarted.addListener(
(stuff) => {console.log(stuff);},
{urls: [/^.*$/]}
);
The domain is insignificant, and I know the regex works, verified in the console. When running this code I get no logging. When I take out the filter parameter I get every request:
webRequest.onResponseStarted.addListener(
(stuff) => {console.log(stuff);}
);
Cool, I'm probably doing something wrong, but I can't see what.
Another approach is to manually filter on my own:
var webRequest = Components.utils.import("resource://gre/modules/WebRequest.jsm", {});
var makeRequest = function(type) {
webRequest[type].addListener(
(stuff) => {
console.log(!stuff.url.match(/google.com.*/));
if(!stuff.url.match(/google.com.*/))
return;
console.log(type);
console.log(stuff);
}
);
}
makeRequest("onBeforeRequest");
makeRequest("onBeforeSentHeaders");
makeRequest("onSendHeaders");
makeRequest("onHeadersReceived");
makeRequest("onResponseStarted");
makeRequest("onCompleted");
With the console.log above the if, I can see the regex returning true when I want it to and the code making it past the if. When I remove the console.log above the if the if no longer gets executed.
My question is then, how do I get the filtering parameter to work or if that is indeed broken, how can I get the code past the if to be executed? Obviously, this is a fire hose, and to begin searching for a solution I will need to reduce the data.
Thanks
urls must be a string or an array of match patterns. Regular expressions are not supported.
WebRequest.jsm uses resource://gre/modules/MatchPattern.jsm. Someone might get confused with the util/match-pattern add-on sdk api, which does support regular expressions.

Youtube Channel Gallery getting no longer supported video from YouTube

Suddenly the feed on our homepage has the - This device is no longer supported - video from YouTube. Everyone is seeing this no matter what device they are on, so we think it doesn't like something about the plugin now after YouTube changed and knew they would not be seen on certain devices and televisions: https://youtube.com/devicesupport
What is the fix for this? Are you pushing out an update to address this? Thanks.
https://wordpress.org/plugins/youtube-channel-gallery/
I would recommend taking a read through this thread in the support forum for the plugin:
https://wordpress.org/support/topic/getting-no-longer-supported-video-from-youtube
There are some different solutions, depending on whether you are using the widget or shortcode, but a few different approaches came up depending on what is easiest for you - personally, I favor this one:
open the file wp-content/plugins/youtube-channel-gallery.php
goto line 622 and paste this (directly under the foreach-line): if ($entry->title == 'https://youtube.com/devicesupport') { continue; }
let the plugin display 1 more video than before (maxitems)
What it does is: just throws away the "device support" video from the video feed. so there's one video less now, this is why you have to add 1 to the maxitems.
*Credit goes to Wordpress.org forums member "koem"
I had the same issue for the youtube videos and I fixed as follows:
After the installation of the youtube plugin in our site, we can see that the folder with the file name youtube-feeder.php
There is a function named "getFeedUrl" and this function is calling from the function
So the line is:
$dataURL ="To get the above URL please follow the below step";
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list
put the part as contentDetails and forUsername as [channel id] eg:Google
then execute then find the "uploads": "UUK8sQmJBp8GCxrOtXWBpyEA" from the list (ID will be different for your channel)
then go to the following:
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.playlistItems.list
Then put the part as snippet and paste the copied uploads id in the playlistId then execute. you can see the result and you just copy the Request URL from the result.
Note: you need to register your application for API_KEY
developers.google.com/youtube/registering_an_application
Second:
You need to change the parsing section also:
OLD code:
$entries = array();
if($data && is_array($data['feed']['entry']))
{
foreach($data['feed']['entry'] as $vid)
{
$vid = $vid['media$group'];
$url = $vid['media$content'][0]['url'];
$url = substr($url, 0, stripos($url, '?'));
$entries[] = array(
'id' => $vid['yt$videoid']['$t'],
'url' => $url,
'title' => $vid['media$title']['$t'],
'date' => $vid['yt$uploaded']['$t'],
'content' => $vid['media$description']['$t']
);
}
}
New Modification:
$entries = array();
if($data && is_array($data['items']))
{
foreach($data['items'] as $vid)
{
//var_dump($data['items']);
$vid = $vid['snippet'];
$url = "https://www.youtube.com/watch?v="+$vid['resourceId']['videoId'];
//$url = substr($url, 0, stripos($url, '?'));
$entries[] = array(
'id' => $vid['resourceId']['videoId'],
'url' => $url,
'title' => $vid['title'],
'date' => $vid['publishedAt'],
'content' => $vid['description']
);
}
}
Then check it out, If its not coming the exact data, please comment the following line also.
`if(!$entries = $this->getCachedYoutubeData($id, $cache, $type, $orderby))`
Please write here if you have.
Youtube API 3 is very different from API 2. I just switched plugins - wpyoutubevideogallery.com - easy to setup and fully functional with youtube API 3. Also free.

Resources