PODIO API call get excel using CURL, authentication error - php

I'm trying to follow this tutorial about REST API call of PODIO using CURL on my localhost.
I was able to get through on the step on getting the app authorized and I have now the authorization code on URL. But it seems I'm not getting response for access token I'm getting an error Undefined property: stdClass::$access_token using the code below. When I tried to do a print_r of variable $tokenresult to see those token response there's an error unexpected '$token_result' (T_VARIABLE). For advice you can give, thank you so much in advance!
<?php
$ch1 = curl_init('https://podio.com/oauth/token?grant_type=authorization_code&client_id=app_ID_i_got_on_PODIO_API key&redirect_uri=http://localhost/PODIO_API/podio-php/podiocurlrequest.php&client_secret=client_secret_key_i_got_fromPODIO_API_key &code=authorization_i_got_from_the_URL');
//curl_setopt($ch1, CURLOPT_TIMEOUT, 400);
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt( $ch1, CURLOPT_SSL_VERIFYPEER, 0 );
//curl_setopt($ch1, CURLOPT_POSTFIELDS, $data_array);
curl_setopt( $ch1, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch1, CURLOPT_RETURNTRANSFER, 1 );
$result1 = curl_exec($ch1);
curl_close($ch1);
$tokenresult = json_decode($result1);
$token = $tokenresult->access_token;
$token1 = "OAuth2 ".$token;
$headers = array(
"Authorization:".$token1
);
$podioch = curl_init('https://api.podio.com/item/app/my app id here/xlsx/&limit=500');
curl_setopt($podioch, CURLOPT_HTTPHEADER, $headers); //load all header data
curl_setopt($podioch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt( $podioch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $podioch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $podioch, CURLOPT_RETURNTRANSFER, 1 );
$resultdat = curl_exec($podioch);
curl_close($podioch);
?>

Have you thought about using Podio PHP client?
That should handle integration with Podio much nicely.
Please have a look at https://github.com/podio/podio-php and http://podio.github.io/podio-php/

visit below url for answer
https://stackoverflow.com/a/19149687/2240290
If you are on localhost then do this to resolve the issue.

Related

google chat bot webhook not working in php

Google chatbot has a webhook where users can automate chat there is a small python script to make it work but I want to do the same using php. I am using curl to hit the post method
$apiUrl = 'https://chat.googleapis.com/v1/spaces/AAAAbvoeZ0w/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=h2OIcCLB6_f_XxhPX6lugnGizE88ZBBpJURFHtPfh_0%253D';
$ch = curl_init($apiUrl);
//$kid_userid = "IXM_".session('user_data')['userID'];
$data = '{"text": "All Mock Test are Free "}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
after hitting this code I am getting errors.
{
error: {
code: 400,
message: "Invalid request token h2OIcCLB6_f_XxhPX6lugnGizE88ZBBpJURFHtPfh_0%3D",
status: "INVALID_ARGUMENT"
}
}
but same code when I am running on python it is working perfectly. Any Help will be very helpful. Thanks for the help in advance and I tried my best to explain .Sorry If I have made any mistake.
This code works for me. I have it from another SO answer, maybe the issue is the missing CURLOPT_POST...
$uri = "https://chat.googleapis.com/v1/spaces/AAAAgcWhzwk/messages?key=MY_KEYI&token=MY_TOKEN";
$msg = '*Testing Curl PHP message to Google Chat*\n\n Description';
$params = '{"text": "'.$msg.'"}';
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
The above code which I have shared is correct actually I just added the new bot URI and it worked. THanks, everyone for your help.

Unable to get embed token of power bi report in php after successfully generating its access token

I am using get/post request to generate embed token of the powerbi report in php and i successfully generated the access token by following the example given in this link https://community.powerbi.com/t5/Developer/How-To-Get-embed-token-using-Get-Post-only/td-p/294475 but when i used this access token to generate embed token for me it returns empty array in response.This is my code
$headers = array(
"Authorization: Bearer <acesstoken generated>"
);
$url = 'https://api.powerbi.com/v1.0/myorg/groups/<group-id>/reports/<report-id>/GenerateToken';
$post_params = array(
'accessLevel' => 'View',
'datasetId'=>'<dataset-id>'
);
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_params);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
echo $response;
Any help would be appreciated thanks.
After the hardwork of 1 day I finally figured out i was using application id in the resource param for generating access token instead of this https://analysis.windows.net/powerbi/api link. So when i used this link ,the problem is solved and generated the embed token successfully.

Access web api using access token in MS Dynamics using php

For Previous question about Azure account, I can create an app using azure account.
Now I can get auth code from below url:
Auth_code
From Auth_code we can get the access token by:
$auth_code = $_GET['code'];
$result = access($auth_code);
function access($auth_code){
$redirectUri = 'https://XXXX /authorize.php';
$token_request_data = array (
"grant_type" => "authorization_code",
"code" => $auth_code,
"redirect_uri" => $redirectUri,
"client_id" => "client_id",
"client_secret" => "client_secret",
"resource" =>"resource" (From manifest in azure)
);
$token_request_body = http_build_query ( $token_request_data );
$curl = curl_init ( 'https://login.windows.net/common/oauth2/token' );
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $curl, CURLOPT_POST, true );
curl_setopt ( $curl, CURLOPT_POSTFIELDS, $token_request_body );
curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER,false);
$response = curl_exec ( $curl );
$res = json_decode($response);
curl_close ( $curl );
Now I'm trying to access the web api using that access_token,I couldn't get the result.
For example:
$authHeader = 'Authorization:Bearer access_toke';
$ch = curl_init();
$url = 'https://domain/api/data/v8.0/contacts';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($authHeader, 'Content- Type:application/json'));
$result = curl_exec($curl);
echo "<pre>";print_r($result);exit;
curl_close($curl);
I'm getting empty response. Now I have to know how to access the web API using access token.
When I try to run manually https://domain/api/data/v8.0/contacts, I can get all contacts in my crm.But when I try to access it by access_token using php,it returns empty.
Web api reference url : reference for web api url
Refer to the guide Compose HTTP requests and handle errors, as the requirements shown at HTTP headers section:
Every request should include the Accept header value of application/json, even when no response body is expected.
And there are supernumerary blank in your PHP script at curl_setopt($curl, CURLOPT_HTTPHEADER, array($authHeader, 'Content- Type:application/json'));
You can remove the blanks in Content-Type and try again.
By the way, you can leverage Fiddler to capture the requests from your PHP client. We you get the response body content and request status code via the tool. We can match the status code with the list at https://msdn.microsoft.com/en-us/library/gg334391.aspx#bkmk_statusCodes. If the code is always 200 without response body, you may check your code in web api.

Eventbrite API simple access token request doesn't work

My code, which actually perfectly works with Linkedin and Meetup APIs, doesn't work with Eventbrite API and I definitely don't understand why :
$params = array(
'grant_type' => 'authorization_code',
'client_id' => EVENTBRITE_CONSUMER_KEY,
'client_secret' => EVENTBRITE_CONSUMER_SECRET,
);
// Eventbrite API access token request
$url = 'https://www.eventbrite.com/oauth/token?' . http_build_query($params);
// Tell streams to make a POST request
$context = stream_context_create(array('http' => array('method' => 'POST')));
// Retrieve access token information
$response = file_get_contents($url, false, $context);
I precise that the API login part to get the authorization code seems to work perfectly well.
Here is the PHP error :
Warning: file_get_contents(https://www.eventbrite.com/oauth/token?grant_type=authorization_code&client_id=ZZ6PPQOMTKSXIHEKLR&client_secret=QQDDIS4RBZXI6ONO7QEYEUZ4JB2ABQQG6K3H7CBD6M5QWK5GSK&code=O63YZASRAYMOUHRMH5AH): failed to open stream: HTTP request failed! HTTP/1.1 400 BAD REQUEST in /var/www/include/actions.php on line 102
Thanks by advance if anybody has a clue :)
UPDATE :
I finally found where is the problem (even if I don't understand why) :
file_get_contents doesn't seem to be a good method to access the oauth page, I used curl instead :
$request_url = 'https://www.eventbrite.com/oauth/token';
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);
I hope it will help anybody encountering the same issue ;)
Just so that this question doesn't continue to show up as unanswered in an auto-email, I'm going to add your answer from your update here -- hope that's alight!
file_get_contents doesn't seem to be a good method to access the oauth page, I used curl instead:
$request_url = 'https://www.eventbrite.com/oauth/token';
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);
Thanks for making it easy by answering your own question! ;)

Login throw curl and browser

I'm working with drupal 7 and REST api.
I'd like to log in into drupal with curl and later when i visit the website with a browser i want to be logged in.
i'm usin gthis code:
<?php
$user_data = array(
'username' => 'usertest',
'password' => 'pass',
);
$ch = curl_init();
$tmpfname = dirname(__FILE__).'/'.$_COOKIE['PHPSESSID'].'.txt';
curl_setopt($ch, CURLOPT_URL, "http://example.com/networklogin/user/login");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $user_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $tmpfname );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $tmpfname );
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
And it works pretty well, it logs the user in, but when i visit "example.com" i'm not logget in as "usertest".
Is there any way to log me into Drupal and allow me to access with a browser?
The goal is to log me in into many website with the same users when i log in into one as i wrote here (Same webserver, same drupal, same db, single sign on?).
Ok, i found a solution here:
Login to website through CURL and client browser
Use curl cookies for the user browser is pretty impossible..

Categories