I'm working on InfusionSoft API (documentation here) and making request by using CURL (no API SDK) but getting the following error.
Failed to parse XML-RPC request: Premature end of file.
any help would be appreciated. Below is the CURL code that I'm using.
$url_token = 'http://api.infusionsoft.com/crm/xmlrpc/v1/?access_token='.$access_token;
$curlPost = array(
'access_token' => $access_token,
'privateKey' => $api_key,
'contactId' => 6171,
'selectedFields' => array('email')
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_token);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($curlPost));
$res = curl_exec($ch);
echo $res;
Related
Stuck trying to get an api-connection to work. I believe I don't understand the below example request in the api. Especially the last row "grant_type..etc". How is this line to be handled in CURL? As POSTFIELDS? Get an error {"error":"unsupported_grant_type"}
POST /connect/token HTTP/1.1
Authorization: Basic base64(client_id:client_secret)
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
"grant_type=authorization_code&code=<authorization_code>&redirect_uri=<redirect_uri>"
Code so far:
$ch = curl_init('https://xxxx');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/x-www-form-urlencoded;charset=UTF-8',
'Authorization: Basic '.base64_encode($clientid.':'.$clientsecret).''
));
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'code' => $_GET['code'],
'redirect_uri' => $redirecturi,
'grant_type' => 'authorization_code'
));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
https://auth0.com/docs/applications/reference/grant-types-available
Here all grant type are explained .
I am polling live prices from the Skyscanner API. Although I receive the session_key and although I am immediately polling the results I am getting a 410 (Gone) response header with an empty body. It used to work fine from my localhost environment but not on my live server anymore.
Has anybody experienced this before and can maybe give me a hint what the issue could be?
$url_api = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/";
$api_key = "XXX"; // Not shown here
$data = array('apiKey' => $api_key, 'country' => 'DE', 'currency' => 'EUR',
'locale' => 'de-DE', 'originplace' => 'HAM', 'destinationplace' => 'AMS', 'cabinclass' => 'economy', 'outbounddate' => '2017-01-27',
'inbounddate' => '2017-01-30' , 'locationschema' => 'Iata', 'groupPricing' => true);
$httpdata = http_build_query($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_api);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $httpdata);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
$response = curl_exec($ch);
curl_close($ch);
$headers = get_headers_from_curl_response($response);
$url = $headers['Location']."?apiKey=".$api_key."&stops=0";
echo $url;
return;
I currently use file_get_contents() to call the LinkedIn Authentication API.
I successful call /uas/oauth2/authorization but when I call /uas/oauth2/accessToken with file_get_contents() it times out.
The odd thing is that it works perfectly on my localhost.
I've made sure allow_url_fopen is on and manage to open google.com with file_get_contents().
As you can probably imagine, it's driving me crazy trying to debug it (and fix it).
Do any of you have any suggestions on why this is the case?
The issue is because /uas/oauth2/accessToken requires a POST type method, file_get_contents always uses GET. Consider switching to curl, method for both of your calls are provided below.
This information is available within the documentation
Variables for both calls
$apiKey = '';
$state = '';
$scope = '';
$redirectUri = '';
/uas/oauth2/authorization
$postData = http_build_query(
[
'response_type' => 'code',
'client_id' => $apiKey,
'scope' => $scope
'state' => $state,
'redirect_uri' => $redirectUri
]
);
$ch = curl_init();
$endpoint = sprintf('%s?%s', 'https://www.linkedin.com/uas/oauth2/authorization', $postData);
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$response = curl_exec($ch);
/uas/oauth2/accessToken
$postData = http_build_query(
[
'grant_type' => 'authorization_code',
'client_id' => $apiKey,
'scope' => $scope
'state' => $state,
'redirect_uri' => $redirectUri
]
);
$ch = curl_init();
$endpoint = 'https://www.linkedin.com/uas/oauth2/accessToken';
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$response = curl_exec($ch);
I have a few subscriptions. Time to time subscription ends and I start the ended subscription again.
Now, my most used subscriptions ended and I can't start again. I'm working in PHP. Nothing has changed in my code, but now I get error while trying to subscribe.
{"meta":{"error_type":"APISubscriptionError","code":400,"error_message":"Invalid response"}}
My other subscriptions are still active but 4 of them are failing. I couldn't fix it.
Edit - Code:
<?php
echo $_GET['hub_challenge'];
$client_id='XXXXX';
$client_secret='XXXXX';
$object = 'tag';
$aspect = 'media';
$object_id = 'XXXXX';
$verify_token='XXXXX';
$callback_url = 'http://XXXXX/callback.php';
$attachment = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'object' => $object,
'object_id' => $object_id,
'aspect' => $aspect,
'verify_token' => $verify_token,
'callback_url'=>$callback_url
);
$url = "https://api.instagram.com/v1/subscriptions/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close ($ch);
print_r($result);
Instagram sends a GET request to uour callback_url and wants you to response with hub.challenge.
I have the following code in php:
define("TOKEN_URL", "https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13");
$arrData = array(
'grant_type=client_credentials',
'client_id='.CLIENT_ID,
'client_secret='.urlencode(ACCESS_KEY),
'scope=urn%3aWindowsAzureMediaServices'
);
$arrHeader = array(
'Content-length:'.strlen($this->generateData($arrData))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, TOKEN_URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->generateData($arrData));
curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeader);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$arrToken = json_decode($data);
I am unable to get the token code. Please can anyone check what could be wrong?
There could be a few issues:
You could simplify a few things and use http_build_query():
$data = http_build_query(array(
'grant_type' => 'client_credentials',
'client_id' => CLIENT_ID,
'client_secret' => ACCESS_KEY,
'scope' => 'urn:WindowsAzureMediaServices',
));
$ch = curl_init(TOKEN_URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (($res = curl_exec($ch)) === false) {
die(curl_error($ch));
}
$arrToken = json_decode($res);
If there's an error, the first thing to make sure is whether you have an updated list of CA certificates.