I am trying to upload an image using linkedin api.
I already uploaded image in my server and now I want to upload the upoaded image url to linkedin. But I got the error
{ "serviceErrorCode":0,"message":"The request is not a multipart
request","status":400 }
$curl1 = curl_init();
$m_url="https://api.linkedin.com/media/upload";
$curl_header = array("Authorization:Bearer ".$access_token);
$uploadRequest = array(
'name'=>'media',
'filename' => basename($medias[0]),
'media_data' => base64_encode(file_get_contents($medias[0]))
);
curl_setopt_array($curl1, array(
CURLOPT_URL => $m_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>$uploadRequest,
CURLOPT_HTTPHEADER=>$curl_header,
));
$response1 = curl_exec($curl1);
$err1 = curl_error($curl1);
curl_close($curl1);
This is the request. Please anyone tell me What is the exact issue and how to sort this out.Thanks in advance.
Added header like this:
$curl_header=array("Content-Type:multipart/form-data",
"Authorization:Bearer ".$access_token);
And changed the post params like this
$curl1 = curl_init();
$m_url="https://api.linkedin.com/media/upload";
$uploadRequest['file'] = new CURLFile($img, 'image/png', basename($img));
$curl_header=array("Content-Type:multipart/form-data", "Authorization:Bearer ".$access_token);
curl_setopt_array($curl1, array(
CURLOPT_URL => $m_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>$uploadRequest,
CURLOPT_HTTPHEADER=>$curl_header,
));
$response1 = curl_exec($curl1);
$err1 = curl_error($curl1);
$status1 = curl_getinfo($curl1, CURLINFO_HTTP_CODE);
curl_close($curl1);
Related
I am trying to send an audio voice sms using an API call, but end up getting the error message {"message":"The voice file must be a file.","status":"error"}
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://example/api/send',
CURLOPT_HTTPHEADER => ['api-key: keyxxx='],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => http_build_query([
'recipients' => [
'233550000000'
],
'voice_file' => new CURLFILE('voice_message.mp3'),
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
I'm trying to cancel the order from Shipstation for That I've write a code
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://ssapi.shipstation.com/orders/".$order_id,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_USERPWD => "$public_key:$private_key",
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
echo "here";
now when I run this API it returns nothing no error no issue no success message same order is also not deleted from Shipstation when I try to pass wrong Public or Private key then it gives me an Error
401 Unauthorized
it means that API call is going correctly because I'm getting response but when I pass the correct creds then it gives no response.
Edit
Now I'm trying
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://ssapi.shipstation.com/orders/".$order_id,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => array(
"Host: ssapi.shipstation.com",
"Authorization:Basic __MY_AUTH_HERE__",
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Now it is giving me an Error
{"Message":"Authorization has been denied for this request."}
where I've created my Auth like
$auth = base64_encode($username_api_key.":". $password_api_secret);
What is the issue and how to fix that?
Thanks
I am trying to upload the image to database using api
$curl = curl_init();
$headers = array("Content-Type: multipart/form-data",);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt_array($curl, array(
CURLOPT_URL => 'api url',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('file'=> new CURLFILE($_FILES['cfile']['tmp_name'])),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
In this code image is not getting store as expected CURLOPT_POSTFIELDS => array('file'=> new CURLFILE($_FILES['cfile']['tmp_name']))
There's a free weather API in my country that I want to use to get rain data. The request is simple https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826 and there's no authentication. If I try the request using Postman, my browser or AJAX, it works fine and I get the results I need. However, using cURL, I get nothing.
Here's the PHP code that I tried:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
I have the cURL.dll installed and tested in another server, but it didn't work.
Is there a problem with the code or is it the API that blocks PHP requests?
its look like this website looking for user-agent header.
try this:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'User-Agent: something'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Am trying to get onedrive access token.
Here is the Request:
GET https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={client_id}&scope={scope}
&response_type=token&redirect_uri={redirect_uri}
Here is Response:
https://myapp.com/auth-redirect#access_token=EwC...EB
&authentication_token=eyJ...3EM&token_type=bearer&expires_in=3600
&scope=onedrive.readwrite&user_id=3626...1d
I have implemented the two code below in other to get the access token but am having error below when page is being redirected for login.
AADSTS900144: The request body must contain the following parameter: 'client_id'.
Scope property is space seperated hence see onedrive documentation link
code 1
$data_string = array(
"client_id" => "myclient id",
"response_type" => "token",
"redirect_uri" => "http://localhost/test/callback.php"
"scope" => ['files.readwrite', 'offline_access'],
);
$data = json_encode($data_string);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "$data",
));
$result = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
code 2
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=myclientid-goes-here&scope=files.readwrite.all offline_access
&response_type=token&redirect_uri=http://localhost/test/callback.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
//CURLOPT_POSTFIELDS => "$data",
));
$result = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
This was resolved using http_build_query() function
hence
$data = http_build_query($data_string, '', '&');