Strava API oAuth Process Token Exchange page can't be reached - php

While I am able to receive the initial Strava oAuth Code through the authorize? process on the Strava page, I am struggling with the token exchange process described here: https://developers.strava.com/docs/authentication/
Code below does only result in
Sorry, this one stays red.
The page you’re looking for doesn’t exist, but you’re not at a dead end.
Here are a few options:
Be sure you have the right url and try again
Sign up or log in at strava.com
See what the community’s been up to at Strava Stories
Search for a particular activity or club
Get a little help from Strava Support
I am quite new to the Strava API, but also directly pasting the resulting URL in the browser does result in the same page response.
$url = "https://www.strava.com/oauth/token?client_id=XXXXX&client_secret=XXXXXXXXXXXXXXXXXXXXXXXX&code=".$code."&grant_type=authorization_code";
echo "<br />".$url;
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
$result = curl_exec($cURL);
curl_close($cURL);
print_r($result);
?>
Thanks in Advance for your support on this matter !

#Chris White solved it, was using POST instead of GET. Thanks for the help
echo "<br />".$url;
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
$result = curl_exec($cURL);
curl_close($cURL);
print_r($result);
?>

Related

How to set APIKEY in PHP CURL call to IBM Natural Language Understanding

I am trying to set the APIKEY value in CURL for authentication to the IBM Natural Language Understanding API in a PHP application.
I have no problem using the ...CURLOPT_USERPWD, "$usname:$pword"... option in my CURL call, but I'm not sure how to use the new API apikey:"xxxxx" method. There is only a apiKey provided now.
I've also tried placing the authorization apikey in my $header_args section like this:
$header_args = array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
'Authorization: apikey:xxxxxxx
);
// Set options for REST call via curl
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $endpointurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //set to 'true' so array returns to $result
//curl_setopt($curl, CURLOPT_USERPWD, "$usname:$pword"); <= this works fine
curl_setopt($curl, CURLOPT_USERPWD, 'apikey:' . $apikey);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header_args);
$result = curl_exec($curl);
I expect that i receive results in $results. instead I receive
{"code":401, "error": "Unauthorized"}
Even I too faced the same issue but with c code.
Firstly you check with the postman whether your endpoints are working, if it is working then there is a problem in your code.
curl_setopt($curl, CURLOPT_USERPWD, 'apikey:' . $apikey); -> did not work for me .
So I sent the API key in the header.
The header format you followed requires small correction it is :
use x-api-key:"apiKey value" instead of Authorization
$header_args = array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
'x-api-key: apikey:xxxxxxx
);

discord php curl login Fail

i want to login into discord with php curl but did't work's for me what is the problem in my code i want auto-login into discord and grab data from html ....!
cloed
There are some advices:
1) If you want to see some responsed information. You have to echo $answer. Otherwise you couldn't see the response even the data were sent correctly.
2) The site used captcha. I tried it with correct email/password and get the following response {"captcha_key": ["captcha-required"]} . I have no idea how to round this. Maybe you should contact the Discord.
3) The site requires json data. Here are the codes I used:
<?php
$data = array("email" => "XXXX", "password" => "XXXX");
$data_string = json_encode($data);
$ch = curl_init('https://discordapp.com/api/v6/auth/login');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$answer = curl_exec($ch);
echo $answer;
if (curl_error($ch)) {
echo curl_error($ch);
}
?>
Hope this will help.

Upload pano image with heading and gps using street View Publish API won't work

I'm trying to upload spherical images on street view using Publish Api.
Upload of image data and place association works well, but whenever i try to upload heading and gps position data to the image server responds "OK" but then no heading nor position were associated to the image.
Here is the php code i use for the last step of info upload, i really don't know where i am wrong.
$data['uploadReference']['uploadUrl']=$upload_url;
$data['pose']['heading']=$heading_north;
$data['pose']['latLngPair']=$latLngPair;
$data['captureTime']['seconds']=time();
$data['places']['placeId']=$placeid;
$data_string = json_encode($data);
$ch = curl_init('https://streetviewpublish.googleapis.com/v1/photo?key='.$_GOOGLE_API['api_key']);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'authorization: Bearer '.$_GOOGLE_API['access_token'],
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
curl_close ($ch);
EDIT:
I've implemented the second step as suggested but nothing changes..
Curl response still doesn't contains any error..
$ch = curl_init('https://streetviewpublish.googleapis.com/v1/photo/'.$photo_id.'?key='.$_GOOGLE_API['api_key'].'&updateMask=pose.heading');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'authorization: Bearer '.$_GOOGLE_API['access_token'],
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$json_response=curl_exec($ch);
curl_close ($ch);
echo $json_response;
EDIT2: this procedure works but google apis are slow and edited data will show up in minutes..
EDIT3 (SOLVED): GET photos (list) has some chache issue. to get the correct value just updated you need to request GET photo (single) to force an effective cache update.
Try to set the values in a second step with photo.update. Don't forget to set the updateMask for the values.

Using cURL to return API XML response

Forgive me if this is simple. My research has brought me to a halt at the moment. I am trying to use cURL to get the response of an API in XML.
This is the URL of the API: https://api.weather.gov/alerts/active/region/land
By default it returns in JSON. Which I know, I should just use the JSON response but, there is a reason I need it in XML as it will seamlessly integrate into my current code until I can rewrite it for JSON.
This is the documentation for the API. Under the API Reference tab is states I just need to change the request header to application/cap+xml. But I am not getting anything back. Just a blank white page.
https://alerts-v2.weather.gov/documentation
Here is my current code I am using to call the API but I get no response or anything. What am I missing?
<?php
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-Type: application/cap+xml;charset=utf-8';
$headers[] = 'Accept: application/cap+xml';
$userAgent = 'php';
$url = 'https://api.weather.gov/alerts/active/region/land';
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPHEADER, $headers);
curl_setopt($cURL, CURLOPT_USERAGENT, $userAgent);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
$result = curl_exec($cURL);
curl_close($cURL);
?>
I've just tried your code and it works fine with atom:
$headers[] = 'Accept: application/atom+xml';
"application/cap+xml" is not available for the URLs, like you mentioned in a question though.
Per the doc https://alerts-v2.weather.gov/documentation the formats are following:
/alerts/active/region/{region} => JSON-LD (default), ATOM
/alerts/{alertId} => JSON-LD (default), CAP

Sending GET request to REST API with custom header

I am trying to send a GET request to a REST API with a custom header, and I've followed tutorials and looked on here, but nothing I tried has worked. Am I missing something from this code?
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://manager.gimbal.com/api/beacons/");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$headers = array(
'Content-type: application/json',
'authorization: Token token={token}',
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($curl);
curl_close($curl);
print($result);
?>
I have the correct token, it worked when I used a REST client.

Categories