How do I use the DailyMotion API? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Can anyone here help me with the integration of the DailyMotion API? I am using their SDK but to no avail, and forums are also not helping much.

I tried using the DailyMotion SDK. It worked very well but later on for some reason I was told not to use SDKs. So here is the PHP code to use the API using cURL.
define("DAILYMOTION_API_KEY", "xyzzz");
define("DAILYMOTION_API_SECRET_KEY", "abcc");
$testUser = "username";
$testPassword = "pwd";
$url = 'https://api.dailymotion.com/oauth/token';
$testVideoFile = "<file location>";
$vidName = "testing video";
$vidDesc = "this is a test";
/* GET ACCESS TOKEN */
try {
$data = "grant_type=password&client_id=" . DAILYMOTION_API_KEY . "&client_secret=" . DAILYMOTION_API_SECRET_KEY . "&username=abs&password=pwd&scope=read+write";
$curlInit = curl_init($url);
curl_setopt($curlInit, CURLOPT_POST, 1);
curl_setopt($curlInit, CURLOPT_POSTFIELDS, $data);
curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curlInit);
curl_close($curlInit);
$res = json_decode($output);
$accessToken = $res->access_token;
$getUploadUrl = "curl -d 'access_token=$accessToken' -G https://api.dailymotion.com/file/upload/";
$uploadUrl = json_decode(system($getUploadUrl));
$postFileCmd = "curl -F 'file=#$testVideoFile'" . ' "' . $uploadUrl->upload_url . '"';
$postFileResponse = json_decode(system($postFileCmd));
$postVideoCmd = "curl -d 'access_token=$accessToken&url=$postFileResponse->url' https://api.dailymotion.com/me/videos";
$postVideoResponse = json_decode(system($postVideoCmd));
$videoId = $postVideoResponse->id;
$publishCmd = "curl -F 'access_token=$accessToken' \
-F 'title=$vidName' \
-F 'published=true' \
-F 'description=this is a test' \
https://api.dailymotion.com/video/$videoId";
$publishres = system($publishCmd);
print_r($publishres);
echo "Video is posted & published Successfully";
} catch (Exception $e) {
print_r($e);
}

Related

I'm trying to get an PHP Curl script working [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 days ago.
Improve this question
I'm trying to get an PHP Curl script working but all I get is:
HTTP Status 400 - type Status report description The request sent by the client was syntactically incorrect.
My Code:
$ch = curl_init();
$clientId = "fd2ff35ee3xxxxxx";
$clientSecret = "780f7671b6e6bxxxxxxx";
$lockId = "24451";
$keyboardPwdType = "3";
$keyboardPwdName = "test";
$startDate = "1626945087000";
$endDate = "1636945087000";
$date = "1626945087000";
$fields = array('clientId'=>$clientId, 'clientSecret'=>$clientSecret, 'lockId'=>$lockId, 'keyboardPwdType'=>$keyboardPwdType, 'keyboardPwdName'=>$keyboardPwdName, 'startDate'=>$startDate, 'endDate'=>$endDate, 'date'=>$date);
$postvars = '';
foreach($fields as $key=>$value) {
$postvars .= $key . "=" . $value . "&";
}
$url = "https://euapi.ttlock.com/v3/keyboardPwd/get";
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST, 1); //0 for a get request
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,3);
curl_setopt($ch,CURLOPT_TIMEOUT, 20);
$response = curl_exec($ch);
print "curl response is:" . $response;
curl_close ($ch);
}
And this is the CURL code that works with SSH:
curl --location -g --request POST 'https://euapi.ttlock.com/v3/keyboardPwd/get' \
--data-urlencode 'clientId=fd2ff35ee3xxxxxx' \
--data-urlencode 'accessToken=780f7671b6e6bxxxxxxx' \
--data-urlencode 'lockId=24451' \
--data-urlencode 'keyboardPwdType=3' \
--data-urlencode 'keyboardPwdName=test' \
--data-urlencode 'startDate=1626945087000' \
--data-urlencode 'endDate=1636945087000' \
--data-urlencode 'date=1626945087000'
Anyone a solution i'm missing? Thanks!
I tryed different codes and options presented on Google and Stackoverflow, none working.

Getting error "InvalidAddress" while submitting Amazon MWS CreateInboundShipmentPlan [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 days ago.
Improve this question
I am using Amazon MWS CreateInboundShipmentPlan to create shipment plan and it is working quite good if I limit my product under 23-24 but If I try to submit more than 24 it gives me InvalidAddress error.
I am using PHP API to submit a request to Amazon MWS. In initial troubleshoot I think its all about the URL length because if I increase the URL length by adding more SKU's it starts giving problem.
If I try with limited number of SKU's I get successful result.
But if I try with more SKU's it gives me
[Error] => Array
(
[Type] => Sender
[Code] => InvalidAddress
[Message] => Resource /errors/mws.amazonservices.com/500.html is not found on this server.
)
Here is my PHP code.
function amazon_CreateInboundShipmentPlan($amazonAWSAccessKeyId,$amazonSellerId,$amazonMWSAuthToken,$amazonMarketPlaceId,$amazonSecretKey,$domain,$extras){
$param = array();
$param['AWSAccessKeyId'] = $amazonAWSAccessKeyId;
$param['Action'] = 'CreateInboundShipmentPlan';
$param['SellerId'] = $amazonSellerId;
$param['MWSAuthToken'] = $amazonMWSAuthToken;
$param['SignatureMethod'] = 'HmacSHA256';
$param['SignatureVersion'] = '2';
$param['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version'] = '2010-10-01';
$param = array_merge($param,$extras);
$secret = $amazonSecretKey;
$url = array();
foreach ($param as $key => $val) {
$key = str_replace("%7E", "~", rawurlencode($key));
$val = str_replace("%7E", "~", rawurlencode($val));
$url[] = "{$key}={$val}";
}
$amazon_feed = '';
sort($url);
$arr = implode('&', $url);
$sign = 'POST' . "\n";
$sign .= 'mws.amazonservices.'.$domain.'' . "\n";
$sign .= '/FulfillmentInboundShipment/'.$param['Version'].'' . "\n";
$sign .= $arr;
$signature = hash_hmac("sha256", $sign, $secret, true);
$httpHeader = array();
$httpHeader[] = 'Transfer-Encoding: chunked';
$httpHeader[] = 'Content-Type: application/xml';
$httpHeader[] = 'Content-MD5: ' . base64_encode(md5($amazon_feed, true));
$httpHeader[] = 'Expect:';
$httpHeader[] = 'Accept:';
$signature = urlencode(base64_encode($signature));
$link = "https://mws.amazonservices.".$domain."/FulfillmentInboundShipment/".$param['Version']."?";
$link .= $arr . "&Signature=" . $signature;
echo strlen($link)."\n";
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $amazon_feed);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$errors=curl_error($ch);
curl_close($ch);
$xml = simplexml_load_string($response);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
return $array;
}
I think there is some problem with the URL length. Please help me to figure out what's exactly wrong with this code.
I finally figure out the problem. Its a url limit problem I changed my method of posting data from GET to POST and it resolved the issue.

HTTP ERROR 500 keep showing up with my php coding [duplicate]

This question already has answers here:
apache & php 500 error nightmares
(1 answer)
php return 500 error but no error log
(12 answers)
Closed 5 years ago.
<?php
if(isset($_POST['ccode']) && isset($_POST['mobile'])){
// Authorisation details.
$username = "stravin123#gmail.com";
$hash = "eb88119d3e9cdc20634c62f6493644ff94dec1b60597f68459becfb7ae0a7e96";
// Config variables. Consult http://api.txtlocal.com/docs for more info.
$test = "0";
// Data for text message. This is the text message data.
$sender = "Visitor Management Team"; // This is who the message appears to be from.
$numbers = $_POST ['ccode'].$_POST['mobile']; // A single number or a comma-seperated list of numbers
$message = $_POST['msg'];
// 612 chars or less
// A single number or a comma-seperated list of numbers
$message = urlencode($message);
$data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
$ch = curl_init('http://api.txtlocal.com/send/?');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch); // This is the result from the API
if($result ==true){
echo "Message has been sent";
curl_close($ch);
}
?>
This is my php code. Whenever I try to access it, it keep showing HTTP ERROR 500. I am currently using hostinger. Please help. Thanks in advance

Extract data from url (PHP) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
http://accounts.fstatic.org/json/results/?callback=google
I need extract all results from here.
Edit: Extract results by id: example
$result1 = result['1'];
$result2 = result['2'];
Use curl to fetch data and decode the json to array in php.
<?php
$json=fetchPageFromURL('http://accounts.fstatic.org/json/results/?callback=google');
$obj=json_decode($json,true);
print_r($obj);
echo "<hr>";
foreach ($obj as $key => $value) {
foreach (array('result','url','v-url','title','content') as $nnn => $keyname) {
if(0===strpos($key, $keyname)){
$id=substr($key, strlen($keyname), strlen($key)-strlen($keyname));
$fin[$id][$keyname]=$value;
}
}
}
print_r($fin);
function fetchPageFromURL($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
?>
Updated to fetch details and put them away.
$results = json_decode(file_get_contents('http://accounts.fstatic.org/json/results/?callback=google'));

How to fetch information from rest in php? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to fetch information from rest in php?
I have an url and I wanna extract information from web service by php.
Example of calling GET request
//next example will recieve all messages for specific conversation
$service_url = 'http://example.com/api/conversations/[CONV_CODE]/messages&apikey=[API_KEY]';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
}
echo 'response ok!';
var_export($decoded->response);
Reference : How to make REST calls in PHP
You can execute curl if is enable on your host.

Categories