I am trying to make a request to get the static map OR trip receipt of a past uber ride.
$headers = array(
"Authorization: Bearer {$this->token}",
'Accept-Language: en_US',
'Content-Type: application/json'
);
curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.uber.com/v1.2/requests/my-request-id-xxx/receipt');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // So it doesnt print out results
$curl_results = curl_exec($curl);
curl_close($curl);
// Uber Responds with JSON
$curl_results = json_decode($curl_results, TRUE); print_r($curl_results);
The response is this:
Array
(
[message] => Forbidden
[code] => forbidden
)
I've refreshed my token and also received new tokens and triple checked to make sure I had selected the correct scopes. I understand that this is a privilege scope and the account I am trying to access is my own account. My only explanation is to what could be happening is that under the API account my email is marked as "Owner" rather than "developer". Could this be the reason why I am being denied.. or am I making another mistake?
Uber API for /v1.2/requests/xxx/map and /v1.2/requests/xxx/receipt does not make their data available if your app did not create the request / event. You only have access to /v1.2/history which provides you the following data:
{
"status": "completed",
"distance": 1.4780860317,
"product_id": "a1111c8c-c720-46c3-8534-2fcdd730040d",
"start_time": 1475545183,
"start_city": {
"latitude": 37.7749,
"display_name": "San Francisco",
"longitude": -122.4194
},
"end_time": 1475545808,
"request_id": "fb0a7c1f-2cf7-4310-bd27-8ba7737362fe",
"request_time": 1475545095
}
If you want more data on a particular trip your only option is to go onto the User Home Page dashboard # https://riders.uber.com/trips/request_id, copy the URL SRC of the Google Static Maps image and decode the $_GET[path] parameter :(
Related
Using this documentation I'm trying to test the request using Postman the example on the right side:
$ curl https://subscriptions.zoho.com/api/v1/organizations
-H 'Authorization: Zoho-oauthtoken 1000.41d9f2cfbd1b7a8f9e314b7aff7bc2d1.8fcc9810810a216793f385b9dd6e125f'
-H 'X-com-zoho-subscriptions-organizationid: 10234695'
Maybe I'm not setting the parameters right but this is how it looks for the moment.
A new GET Request, in the url input: https://subscriptions.zoho.com/api/v1/organizations
And under that, in the Headers tab I added two key-value pairs:
Authorization: Zoho-oauthtoken 1000.41d9f2cfbd1b7a8f9e314b7aff7bc2d1.8fcc9810810a216793f385b9dd6e125f
Authorization: X-com-zoho-subscriptions-organizationid: 1023469
The returned result:
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
</body>
</html>
If I deleted the second key-value pair it returns this JSON:
{
"code": 57,
"message": "You are not authorized to perform this operation"
}
What is wrong with my approach?
Can you try this?
If you are sure of the api url, do validate the token and create a fresh token and
add it to header as below:
HeaderName : Authorization
HeaderValue: 1000.41d9f2cfbd1b7a8f9e314b7aff7bc2d1.8fcc9810810a216793f385b9dd6e125f
HeaderName : X-com-zoho-subscriptions-organizationid
HeaderValue: 10234695
I tried this and is getting,
{
"code": 14,
"message": "Invalid value passed for authtoken."
}
Might be the token got invalid.
Now I tried with a new token generated myself and I am getting now,
{
"code": 0,
"message": "success",
"organizations": [],
}
In short, you have to generate an auth token first and then hit the url with proper header value as shown above.
Thank you :)
I'm trying to use MATLAB's webread function to query Google BigQuery via the REST API, and am having issues. The following curl request is successful:
curl 'https://www.googleapis.com/bigquery/v2/projects/<MyProjectId>/queries' \
-X POST \
-H 'Authorization: Bearer <MyBearerToken>' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data-binary '{"query":"select count(1) from MyTable","useLegacySql":false}' \
--compressed
However, the following MATLAB code:
api = 'https://www.googleapis.com/bigquery/v2/';
access_token = '<MyAccessToken>';
options = weboptions('RequestMethod', 'post');
r = webread([api 'projects/<MyProjectId>/queries?access_token=' access_token], ...
'query', 'select count(1) from MyTable', ...
'useLegacySql', false, ...
options);
generates the following error:
Error using readContentFromWebService (line 45)
The server returned the status 400 with message "Bad Request" in response to the request to URL
https://www.googleapis.com/bigquery/v2/projects/<MyProjectId>/queries?access_token=<MyAccessToken>&query=select+count(1)+from+<MyTable>&useLegacySql=0
Entering the URL in the MATLAB error into a POST requester shows the following (generic) error, so it appears the URL is malformed:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Required parameter is missing"
}
],
"code": 400,
"message": "Required parameter is missing"
}
}
How can I use MATLAB's webread to accomplish the same thing as the above curl request?
It turns out that the webread function doesn't have this functionality. This issue is resolved successfully by using webwrite as follows:
options = weboptions( ...
'RequestMethod', 'post', ...
'MediaType', 'application/json');
data = struct( ...
'query', 'select count(1) from MyTable', ...
'useLegacySql', false);
r = webwrite([api 'projects/<MyProjectId>/queries?access_token=' access_token], ...
data, ...
options);
I'm using Loopback and
I'm trying to user auth for graph api without javascript sdk or passport
I got the code successfully however I can't exchange it with access token
I followed this guide https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/#confirm
my get request is https://graph.facebook.com/v2.7/dialog/oauth?code={xxxx}&client_secret={xxxx}&client_id={xxx}&redirect_uri={myURL}
myURL is the one used to get the code but not be used again if I understand
If I understand correctly I should it the access_token in the body of the response instead I get this error
{
"error": {
"message": "Unknown path components: /oauth",
"type": "OAuthException",
"code": 2500,
"fbtrace_id": "HXe+214tGpW"
}
}
It looks like a bug in the docs. The first call is to www.facebook.com in a browser.
See here for an example client https://github.com/yschimke/oksocial/blob/master/src/main/java/com/baulsupp/oksocial/services/facebook/FacebookAuthFlow.java
The second should be to something like https://graph.facebook.com/v2.7/oauth/access_token
$response = $fb->sendRequest(
'GET',
'/oauth/access_token',
[
'client_id' => $config['client_id'],
'client_secret' => $config['client_secret'],
'grant_type' => 'fb_exchange_token',
'fb_exchange_token' => $short_token
],
$short_token,
null,
'v2.7');
I need to post messages on a Facebook page. Specifically I want to post via cron.
Here's what the API docs say:
Page Access Token – These access tokens are similar to user access tokens, except that they provide permission to APIs that read, write or modify the data belonging to a Facebook Page. To obtain a page access token you need to start by obtaining a user access token and asking for the manage_pages permission. Once you have the user access token you then get the page access token via the Graph API.
How I can obtain a user access and page access token without a page callback? Is this possible?
What you need it an Extended Page Token, it is valid forever. You get one like this:
Authorize with the manage_pages permission (and publish_pages if you want to post as Page later), to get a User Token
Extend the User Token
Use /me/accounts?fields=access_token with the Extended User Token to get a list of all your Pages with Extended Page Tokens - or use /page-id?fields=access_token to get an Extended Page Token for a specific Page
Information about all Tokens and how to extend the User Token:
https://developers.facebook.com/docs/facebook-login/access-tokens#extending
http://www.devils-heaven.com/facebook-access-tokens/
PHP API V5
The below code worked for me after 24 hours of head scratching .... hope this helps by the way if you need this code to work you should have completed the first two steps
Should have login to facebook I used getRedirectLoginHelper
Set session variable with the received user access token on the call back file $_SESSION['fb_access_token'] = (string) $accessToken;
$fbApp = new Facebook\FacebookApp( 'xxx', 'xxx', 'v2.7' );
$fb = new Facebook\Facebook( array(
'app_id' => 'xxx',
'app_secret' => 'xxx',
'default_graph_version' => 'v2.7'
) );
$requestxx = new FacebookRequest(
$fbApp,
$_SESSION['fb_access_token'],//my user access token
'GET',
'/{page-id}?fields=access_token',
array( 'ADMINISTER' )
);
$responset = $fb->getClient()->sendRequest( $requestxx );
$json = json_decode( $responset->getBody() );
$page_access = $json->access_token;
//posting to page
$requesty = new FacebookRequest(
$fbApp,
$page_access ,
'POST',
'/{page-id}/feed?message=Hello fans YYYYYYYYYYYYYYY'
);
$response = $fb->getClient()->sendRequest( $requesty );
var_dump( $response );
You can get the page token this way:
$response = $fb->get('/'.$pageId.'?fields=access_token', (string)$accessToken);
$json = json_decode($response->getBody());
$page_token = $json->access_token;
$response = $fb->post('/'.$pageId.'/feed', $fbData, $page_token);
I've only JavaScript code, but once you have an access token, you may get the pages which can be adminstered by the given user. This will contain a page access token for each of them:
jQuery.ajax({type: "GET",
url: "https://graph.facebook.com/v2.2/me/accounts?access_token=" + userToken,
async: false,
data: jsonRequest,
dataType: "json",
cache: false,
success: function(data)
{
The data given back is like:
{
"data": [
{
"access_token": "CAACni8TcBB0B...cZBJfwZDZD",
"category": "Computers/Technology",
"name": "abc",
"id": "...",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
]
},
{
"access_token": "CAA...ZDZD",
"category": "App Page",
"name": "xyz",
"id": "....",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
]
}
],
access_token is your page token. You may transform the above request into PHP easily.
The API I'm accessing requires a custom authorization header that is a combination of the publicKey that is passed in when the client is instantiated and the complete URI of the API endpoint. I want to pull the baseUrl and operation uri out of the service description and use them to create the authorization header, but I can't figure out how to do this when calling the instantiated client.
This is the service description:
{
"name": "FranchiseSystem",
"apiVersion": "1",
"baseUrl": "https://apidev.example.com",
"description": "REST API client",
"operations": {
"GetFranchiseList": {
"httpMethod": "GET",
"uri": "v1/franchise",
"summary": "Returns an array of franchises."
},
"GetReviews": {
"httpMethod": "GET",
"uri": "v1/review",
"summary": "Returns an array of reviews."
}
}
}
This is the client setup:
$testClient = new JunknetClient([
'publicKey' => '1234567890',
]);
This is the call to the instantiated client with the name of the operation:
$result = $testClient->GetFranchiseList();
or:
$result = $testClient->GetReviews();
When testClient->GetFranchiseList is called, I need to create the authorization header using the publicKey and the values of baseUrl and uri for GetFranchiseList.
When testClient->GetReviews is called, I need to create the authorization header using the publicKey and the values of baseUrl and uri for GetReviews.
You might want to have a look at the following links from the Guzzle docs.
Request Options - Headers
Authentication Parameters
I was able to solve my problem by using and event emitter and subscriber. It's a bit messy, but it get's the job done.
private function handleCredentialsOptions(Collection $config) {
//Build authorization header from $config values
$this->getHttpClient()->getEmitter()->on('before',
function (BeforeEvent $e) use(&$config) {
$this->getHttpClient()->setDefaultOption('headers', [
'Authentication' => '',
]);
$path = $e->getRequest()->getUrl();
$authValue = $config['publicKey'].';;';
$authValue .= time().';';
$authValue .= strtoupper(md5($config['privateKey'] . $path));
$this->getHttpClient()->setDefaultOption('headers', [
'Authentication' => $authValue,
]);
});
}