Search code examples
phpapicurlpodio

PODIO API call get excel using CURL, authentication error


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);

?>

Solution

  • 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/