how to get thumbnail url with Dailymotion api just after a video is uploaded - dailymotion-api

I am trying to retrieve “thumbnail_url” with using API after I just uploaded a video.
However, “thumbnail_url” I retrieved is always this URL “Hhttp://s2.dmcdn.net/KtV-L.jpg” or “Hhttp://s2.dmcdn.net/KtV-L/x240-gK0.jpg” (when I used oEmbed API).
On the other hand, I am able to get “thumbnail_url”that I wanted when I put the URL into the address bar in the browser manually like following URL.
Hhttps://api.dailymotion.com/video/VIDEOID?fields=thumbnail_url
My question is;
Is there time lag or does Dailymotion API need more time to generate a thumbnail image just after a video is uploaded?
Or, is the way to retrieve the thumbnail url I coded wrong?
Here is the code to get thumbnail image url.
*As a prerequisite, I already got access token, created a video and published.
/////////////// Publish a video ///////////////
$publishVideoAPI = "https://api.dailymotion.com/video/".$responseID;
// Post data
$dataPublish = array(
"title" => $videotitle,
"published" => true,
"channel" => "shortfilms",
"tags" => $tags,
"access_token" => $accesstoken
);
$conn = curl_init();
// Post method
curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($conn, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($conn, CURLOPT_RETURNTRANSFER, true);
curl_setopt($conn, CURLOPT_URL, $publishVideoAPI);
curl_setopt($conn, CURLOPT_POST, true);
curl_setopt($conn, CURLOPT_POSTFIELDS, $dataPublish);
// execute
$resPublish = curl_exec($conn);
echo "publish video<br />";
var_dump($resPublish);
// close
curl_close($conn);
/////////////// Grab a thumbnail image of the video start ///////////////
// API
$thumbnail = "https://api.dailymotion.com/video/".$responseID."?fields=thumbnail_url";
// initialise session
$conn = curl_init();
// Get method
curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($conn, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($conn, CURLOPT_RETURNTRANSFER, true);
curl_setopt($conn, CURLOPT_HEADER, false);
curl_setopt($conn, CURLOPT_URL, $thumbnail);
// execute
$res2 = curl_exec($conn);
echo "thumbnail url<br />";
//var_dump($res2);
echo "<br /><br />";
// close
curl_close($conn);
$thumbnailData = json_decode( $res2 , true );
$thumbnailURL = $thumbnailData["thumbnail_url"];
echo $thumbnailURL;

I have all ready execute this code
GET Method this url : https://api.dailymotion.com/video/'+videoID+'?fields=id,thumbnail_url,thumbnail_120_url
Than find response :
{"id":"x2qwonn","thumbnail_url":"http://s2.dmcdn.net/Kra86.jpg","thumbnail_120_url":"http://s2.dmcdn.net/Kra86/x120-aNB.jpg"}
response = {"id":"x2qwonn","thumbnail_url":"http://s2.dmcdn.net/Kra86.jpg","thumbnail_120_url":"http://s2.dmcdn.net/Kra86/x120-aNB.jpg"}
thumbnail = response['thumbnail_120_url'].replace("\","")
get result
http://s2.dmcdn.net/Kra86/x120-aNB.jpg

Thank you for your response.
I figured this out and now uploaded the thumbnail image properly.
As you tested, this code was right.
The reason that the image I uploaded was always same image provided by Dailymotion was that the video status was "processing".
So I put the loop to check the status with 10 seconds interval, and only when the status turned to "published", try to grab the thumbnail image.

Related

APNS Push notification Background non working anymore

Sorry to repost this question as it was asked a few times, but no answer was ok for me.
My app don't wake up anymore on background notification.
So I updated my php script and added HEADERs field as documented here and here
But no luck.
Here my sample code :
<?php
$device_token = 'd98e1d488acac56305a9f83b...b616bc5b5b3bf238dc';
//$device_token = '27b296397f81f48590a....fe2742e0b2a051ae2cefffded85d7';
// Put your private key's passphrase here:
$pem_secret = '';
$pem_file = 'pushcert.pem';
$url = "https://api.development.push.apple.com/3/device/$device_token";
//$body = '{"aps":{"alert":"balbla","badge":0,"sound":"default"}}';
$body = '{"aps":{"content-available":1},"acme1":"bar"}';
$header = ['apns-topic'=>'com.blabla.bla',
'apns-push-type'=>'background',
'apns-priority'=>'5'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSLCERT, $pem_file);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pem_secret);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$information = curl_getinfo($ch);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//On successful response you should get true in the response and a status code of 200
//A list of responses and status codes is available at
//https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW1
//var_dump($header);
//var_dump($information);
var_dump($response);
var_dump($httpcode);
?>
I never enter the iOS methode to catch this notification :
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[NSUserDefaults standardUserDefaults] setValue:userInfo forKey:#"testtesttest"];
// Method called when user click on notification and application is in background
application.applicationIconBadgeNumber = 0;
NSLog(#"did received remote notification"); }
Also in my device console, it seems that the device is canceling my notifications or something a don't get.
Also not that standard notifications (not in Background) works fine.
testing iOS 13.3.1
Thanks a lot for any help you could get me.
Background mode enabled :
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
<string>processing</string>
<string>remote-notification</string>
</array>
App Settings also configured :
I managed to make it Work with that sample code:
<?php
// open connection
if (!defined('CURL_HTTP_VERSION_2_0')) {
define('CURL_HTTP_VERSION_2_0', 3);
}
$device_token = 'd56e9ef8b5ea558f07584cf8...498824ece60a36229446a2003116'; //David
// Put your private key's passphrase here:
$pem_secret = '';
$pem_file = 'pushcert.pem';
$url = "https://api.development.push.apple.com/3/device/$device_token";
$app_bundle_id = "com.blabla.blabla";
//$body = '{"aps":{"alert":"balbla","badge":0,"sound":"default"}}';
$body = '{
"aps":{"content-available":1},
"type":"LOCATION",
"idRequest":"538EAC3E765A4BDC89B554C40F5B14EF"
}';
$headers = array(
"apns-topic: {$app_bundle_id}",
"User-Agent: My Sender",
"apns-push-type:background",
"apns-priority:5"
);
var_dump($body);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PORT,443);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST,TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSLCERT, $pem_file);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
$response = curl_exec($ch);
$information = curl_getinfo($ch,CURLOPT_HTTPHEADER);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//On successful response you should get true in the response and a status code of 200
//A list of responses and status codes is available at
//https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW1
//var_dump($header);
var_dump($information);
var_dump($response);
var_dump($httpcode);
?>
Well at least it seems that the application is waking up (seen in the device log)
So this morning I launch the code from yesterday (with no modifications at all) and it worked for a few times, like 4 or 5 times.
Now it doesn't work anymore. Same as yesterday (iOS system seems to catch the payload, but application is not waked up)
-> conclusion, this a system limitation, and this is so confusing when you need to perfom tests. I'm gonna put this in production with no assurance it will work properly...

Getting the price of Priority Mail Express in USPS shipping

I required to get the rate for standard post,priority mail as well as priority express mail.Using below code i am getting the price rates for priority mail and standard post but not for priority express mail.
When in service column i write the priority express mail then there was an error as given below(Priority mail express)
"The requested Mail Service is not available for the specified request attributes."
Code i am using is this:
{
$url = "http://Production.ShippingAPIs.com/ShippingAPI.dll";
$ch = curl_init();
// set the target url
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
// parameters to post
curl_setopt($ch, CURLOPT_POST, 1);
$data = "API=RateV4&XML=<RateV4Request USERID=\"$userName\"><Package ID=\"1ST\"><Service>All</Service><ZipOrigination>$orig_zip</ZipOrigination><ZipDestination>$dest_zip</ZipDestination><Pounds>$weight</Pounds><Ounces>0</Ounces><Container/><Size>REGULAR</Size><Machinable>FALSE</Machinable></Package>
</RateV4Request>";
// send the POST values to USPS
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
$result=curl_exec ($ch);
$data = strstr($result, '<?');
//echo '<!-- '. $data. ' -->'; // Uncomment to show XML in comments
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);
$params = array();
$level = array();
foreach ($vals as $xml_elem) {
if ($xml_elem['type'] == 'open') {
if (array_key_exists('attributes',$xml_elem)) {
list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
} else {
$level[$xml_elem['level']] = $xml_elem['tag'];
}
}
if ($xml_elem['type'] == 'complete') {
$start_level = 1;
$php_stmt = '$params';
while($start_level < $xml_elem['level']) {
$php_stmt .= '[$level['.$start_level.']]';
$start_level++;
}
$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
eval($php_stmt);
}
}
curl_close($ch);
//print_r($data);exit;
echo '<pre>'; print_r($params); echo'</pre>'; // Uncomment to see the full array
//echo $params['RATEV4RESPONSE']['1ST'][$servicecode]['RATE'];exit;
}
Priority Mail Express is not available for all types of shipments and it might be restricted in this case. Given that your request works for other mailclasses, there's a high likelihood that this is a shipping, not technical issue. It would help if you can share the specific parameters that you're sending.
If you want to play around with USPS shipping rates you can retrieve shipping rates for free with an easy UI or API at https://goshippo.com.

CURL - no url set

$param = 'get.php';
$url = 'http://mysite.org/'. $param;
$__post = 'option=1&option2=225';
mysite.org/get.php - exists for 100%, when I open them in browser everything works.
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $__post);
$result = curl_exec($c);
curl_close($c);
print_r($result); // show 404 o_O
I test it using sniffer and CURL pass URL :
http://mysite.org
not
http://mysite.org/get.php
when I do somethink like that :
curl_setopt($c, CURLOPT_URL,'http://mysite.org/get.php');
everything works fine... so... please help me :D What I do wrong, certainly it is a small error but I don't see where he is :/

Decoding the information from token with janrain

I am using janrain widget for OAuth process on my website. I am testing this in following URL: http://vignesh.gvignesh.org/register/
After clicking the register button, the user is signed in from Google or Yahoo or Facebook. I am able to get the token and store it in a variable. I am displaying the token in my site for testing. Now I don't know how to extract the user information from the token I am getting.
<?php
$rpxApiKey = 'YOUR_API_KEY_HERE';
if(isset($_POST['token'])) {
/* STEP 1: Extract token POST parameter */
$token = $_POST['token'];
/* STEP 2: Use the token to make the auth_info API call */
$post_data = array('token' => $_POST['token'],
'apiKey' => $rpxApiKey,
'format' => 'json');
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, 'https://rpxnow.com/api/v2/auth_info');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$raw_json = curl_exec($curl);
curl_close($curl);
/* STEP 3: Parse the JSON auth_info response */
$auth_info = json_decode($raw_json, true);
if ($auth_info['stat'] == 'ok') {
/* STEP 3 Continued: Extract the 'identifier' from the response */
$profile = $auth_info['profile'];
$identifier = $profile['identifier'];
if (isset($profile['photo'])) {
$photo_url = $profile['photo'];
}
if (isset($profile['displayName'])) {
$name = $profile['displayName'];
}
if (isset($profile['email'])) {
$email = $profile['email'];
}
print $identifier;
echo "</br>";
print $photo_url;
echo "</br>";
print $name;
echo "</br>";
print $email;
/* STEP 4: Use the identifier as the unique key to sign the user into your system.
This will depend on your website implementation, and you should add your own
code here.
*/
/* an error occurred */
} else {
// gracefully handle the error. Hook this into your native error handling system.
echo 'An error occured: ' . $auth_info['err']['msg'];
}
}
?>
This will extract the information from the token which we get after the authentication.

Using basic oauth to send a tweet

I was using basic auth to send tweets from a server every time a song changed. Now they have blocked basic auth and I am not sure how to incorporate it. I have a server at home that updates an html file on the webserver and then calls the following script to tweet out from that file. Any ideas on how to accomplish this simply?
<?php
//====================================================
// CONFIGURATION
//====================================================
// YOUR TWITTER USERNAME AND PASSWORD
$username = '#####';
$password = '#####';
DEFINE(htmlfile, '/homec/public_html/site.com/twitter.html');
$stationURL = "http://www.site.com";
$maxLimit = "139";
$da="";
$f=#fopen(htmlfile, "r");
if ($f!=0)
{
$da=#fread($f, 4096);
fclose($f);
}
else
{
exit;
}
$da=str_replace("\r", "\n", $da);
$da=str_replace("\n\n", "\n", $da);
$d=explode("\n", $da);
$d[0]=trim($d[0], "|"); // title
$d[1]=trim($d[1], "|"); // artist
//====================================================
if ($d[0]=="" || $d[1]=="")
{
// IF WE COULD NOT GRAB THE ARTIST AND
// SONG TITLE FROM THE SAM-GENERATED HTML FILE,
// WE'LL BAIL OUT NOW WITHOUT SUBMITTING ANY TEXT
// TO TWITTER.
exit;
}
else
{
// SUCCESS IN GETTING ARTIST AND TITLE!
// WE'LL PROCEED WITH BUILDING A TEXT STRING TO SUBMIT TO TWITTER.
$message = urlencode('' . $d[1] . ' - ' . $d[0] . ' #bandradio #nowplaying ');
$stationURL = urlencode(' ' . $stationURL);
if ((strlen($message) + strlen($stationURL)) > $maxLimit)
{
// We have to truncate the artist-title string to make room for the station URL string.
$message = substr($message, 0, (($maxLimit - 2) - strlen($stationURL)));
$message .= ".." . $stationURL;
}
else
{
// No need to truncate, it all fits.
$message = $message . $stationURL;
}
} // if ($d[0]=="" || $d[1]=="")
//====================================================
// The twitter API address
$url = 'http://twitter.com/statuses/update.json';
// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
//curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
//curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
$resultArray = curl_getinfo($curl_handle);
curl_close($curl_handle);
Download the latest version of TwitterOAuth from http://github.com/abraham/twitteroauth/downloads Unpack the download and place the twitteroauth.php and OAuth.php files in the same directory as a file with the following code. Register an application at http://dev.twitter.com/apps and from your new apps details page click on "my access token" to get your access token. Fill the four required variables into the script below and you can then run it to post new tweets.
<?php
require_once('twitteroauth.php');
$connection = new TwitterOAuth('app consumer key', 'app consumer secret', 'my access token', 'my access token secret');
$connection->post('statuses/update', array('status' => 'text to be tweeted'));

Resources