What does this Microsoft error message mean? - microsoft-translator

I went to Microsoft developer website and gained a Client ID and Client Secret.
And the following is my source code. I replaced the last two digits with XX
<?php
$ClientID='000000004C12B0XX';
$ClientSecret='yAFqUbNwCqSbs-dQJ5BzF1tWBZggFWXX';
$ClientSecret = urlencode($ClientSecret);
$ClientID = urlencode($ClientID);
// Get a 10-minute access token for Microsoft Translator API.
$url = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13";
$postParams = "grant_type=client_credentials&client_id=$ClientID&client_secret=$ClientSecret&scope=http://api.microsofttranslator.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$rsp = curl_exec($ch);
print $rsp;
?>
And the error message I am getting is
{
"error":"invalid_client",
"error_description":"ACS50012: Authentication failed.
Trace ID: e2f0bfde-d086-4900-ba1f-a58f02693dac
Correlation ID: 3750d010-2e9f-45c5-8ba0-f28dfc050909
Timestamp: 2014-10-20 17:20:26Z"
}

I know, it is very old question, but Microsoft has so many ID's.. I also was confused with "invalid_client" error. Microsoft means Client ID is a value, pointed on https://datamarket.azure.com/developer/applications in "Client ID" column. It is an ID you pointed when created your application. Client ID can be any string, e.g. "myid" is a valid Client ID.
$ClientID='000000004C12B0XX';
Looks like generated value, not user pointed.

Related

Autodesk Forge token reauthorization command doesn't recognize parameters

I am using Laravel / PHP on the back end to communicate with the Forge system. To establish an initial token, I am using the guzzle tool kit. This works fine.
// Get environment variables
$FusionID = getenv('THISID');
$FusionSecret = getenv('THISSECRET');
// Make call to get token with authorization code, client id, and secret
$client = new Client(); //GuzzleHttp\Client
$response = $client->request('POST', 'https://developer.api.autodesk.com/authentication/v1/gettoken', [
'form_params' => [
'grant_type' => 'authorization_code',
'code' => $authCode,
'client_id' => $FusionID,
'client_secret' => $FusionSecret,
'redirect_uri' => 'https://www.example.com/redirect',
'scope' => array('data'=>'create', 'data'=>'read')
]
]);
$body = $response->getBody();
$obj = json_decode($body);
For the numerous other commands, the guzzle protocol seems to have issues so I have been using the straight curl commands. However, I can't seem to get either to work for the refresh token.
I have verified that the variables below have the proper data, but I get the error that
"developerMessage":"The required parameter(s) client_id,client_secret,grant_type not present in the request","userMessage":"","errorCode":"AUTH-008",
I am not sure what to do. Both the guzzle method and the curl method do not seem to be working for me.
$thumbData = '{"client_id":"'.$FusionID.'",
"client_secret":"'.$FusionSecret.'",
"grant_type":"refresh_token",
"refresh_token":"'.$userInfo->refresh_token.'"}';
$url = 'https://developer.api.autodesk.com/authentication/v1/refreshtoken';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $thumbData );
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded'
));
$response = curl_exec ($ch);
$err = curl_error($ch);
curl_close ($ch);
The way you post x-www-form-urlencoded data with Guzzle looks fine so that leaves the question to be whether your Guzzle version is 6+ otherwise use body instead of form_params as your payload option.
With cURL you request body should be delimited by & in x-www-form-urlencoded format like below instead of `json:
curl_setopt($ch, CURLOPT_POSTFIELDS,
"client_id=sb233&client_secret=2333&...");

request a web service from laravel that returns a json object

I have this Url : https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e
when I request it from browser it gives me this response:
{"ip_address":"188.225.179.138","country":"Palestinian Territory, Occupied","country_code":"PS","continent":"Asia","continent_code":"AS","city":"Ramallah","county":null,"region":null,"region_code":null,"timezone":"GMT+2","owner":"COOLNET NEW COMMUNICATION PROVIDER","longitude":35.2,"latitude":31.9}
how can I invoke this url from laravel?
note that I tried this code, but it didn't work.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec();
curl_close($ch);
dd($data);
Thanks in advance.
In the Curl you shall do this Easy 5 steps
Step 1
Initiate the Curl $cSession = curl_init();
Step 2
Define the Curl Url
curl_setopt($cSession,CURLOPT_URL,"https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false);
Step 3
Execute the Curl
$result=curl_exec($cSession);
Step 4
Close the Curl Connection
curl_close($cSession);
Step 5
Print the Result
echo $result;
Putting all together
<?php
$cSession = curl_init();
curl_setopt($cSession,CURLOPT_URL,"https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false);
$result=curl_exec($cSession);
curl_close($cSession);
echo $result;
?>
There is a PHP package for getting an IP address for IP Find that you can install with composer here that works great with Laravel.
https://github.com/tenfef/ipfind-php/

Documentation for Google FIT REST API dataset:aggregate

I am trying to get data from Google Fit using REST API. I am able to get individual data points for steps and calories through the documented REST APIs. However,I want them aggregated by day. I see the following resource in the Oauth2 playground:
https://www.googleapis.com/fitness/v1/users/{userId}/dataset:aggregate
However, I was not able to find any documentation on how to use this. Has anyone been successful in using this REST resource? Any pointers to the documentation / any examples would really help.
Thanks,
This is how i solved this REST call & its working code in my project.
$AccessToken = "TOKEN";
Data['aggregateBy'] =array(["dataTypeName"=>'com.google.step_count.delta',"dataSourceId"=>'derived:com.google.step_count.delta:com.google.android.gms:estimated_steps']);
$Data['bucketByTime']['durationMillis'] =86400000;
$Data['startTimeMillis'] =1487721600000;
$Data['endTimeMillis'] =1487772000000;
$JsonData = json_encode($Data);
$ApiUrl = 'https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate?access_token='.$AccessToken;
$Ch = curl_init();
curl_setopt($Ch, CURLOPT_URL, $ApiUrl);
curl_setopt($Ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($Ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($Ch, CURLOPT_HEADER, 0);
curl_setopt($Ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($Ch, CURLOPT_POST, 1);
curl_setopt($Ch, CURLOPT_POSTFIELDS, $JsonData);
$Result = curl_exec($Ch);
curl_close($Ch);
print_r($Result);

Error file_get_contents with twitter search api

I have the following problem: when this script runs
$url = 'http://search.twitter.com/search.json?q=obama';
$tw = file_get_contents($url,0,null,null);
I receive this message.
Warning (2): file_get_contents(http://search.twitter.com/search.json?q=obama) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 420 Client Error (420)
But it's very strange because it has always been working!
Can you help me?
Adding...I tried to use CURL in this way
$url = 'http://search.twitter.com/search.json?q=obama';
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $url);
$contents = curl_exec($c);
echo $contents;
curl_close($c);
but call returned this message
"error":"You have been rate limited. Enhance your calm."} and it seemed absurd because I didn't make any request before.
I found everywhere that the best practice in this case is use CURL.
I don't know why but then I tried to pass parameter ('obama') with urlencode and it seems to be that syntax (previously incorrect) the main cause of this warning.

curl example of file download doesn't work

If I follow the box api 2.0 curl example to get the metadata of a file, I get the information. When I append /data to the url to download the file, curl says:
curl: (52) Empty reply from server
I did this with two files, both text files, same result.
The system here is OpenBSD 5.0.
In python 3, the same request raises an exception that says that the reply from the server contained a status line that is empty.
I had the same issue. The problem is that you need the CURLOPT_FOLLOWLOCATION option set to true. Box will execute a redirection from the API call to the actual file. Without it, it will return an empty response.
An empty response should be returned in the event that the file itself is empty. If, for instance, the two text files don't have any text in them, no text will be returned i.e. this appears to be expected behavior.
I'm getting the same issue. I have uploaded a file successfully, retrieved the file ID, then when I try to download the file, nothing happens. Like the original poster mentioned, if I take off the "/data" portion of the URL, then I can get all of the info back about the file successfully.
Here is my "download code" that gets called from a form with a simple "Download File" button for that particular file ID.
$boxkey = "ThisIsMyAPIKey";
$auth_token = $_POST['auth_token'];
$url = "https://www.box.com/api/2.0/files/".$_POST['file_id']."/data";
$header = array("Authorization: BoxAuth api_key=".$boxkey."&auth_token=".$auth_token);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_exec($ch);
curl_close($ch);
$url = "https://api.box.com/2.0/files/$fileId/content?access_token=$accessToken";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);