Page 1 of 1

Help: Where can I find a PHP sample to get my Token ?

Posted: Wed Oct 15, 2014 8:56 am
by Bruno
Hi All,

As I'm a newbie with PHP, I would like to know if someone has a little sample in PHP to get my token ?

I created my Apps, so I have my key/secret but I need now this little sample....

thanks for your help,

Actually I do that but no error, no answer, ...nothing ...

Code: Select all

//http://oauth.googlecode.com/svn/code/php/OAuth.php
require './OAuth.php';

$key        = 'xxx...xx';
$secret     = 'xx...xxx';
$consumer   = new OAuthConsumer($key, $secret);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1;

$api_endpoint   = 'https://ops.epo.org/3.1/auth/accesstoken';

$parameters     = array('grant_type'=>'client_credentials');

$req        = OAuthRequest::from_consumer_and_token($consumer, null, "POST", $api_endpoint, $parameters);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$req->sign_request($sig_method, $consumer, null);

$ch = curl_init($req->to_url());
$result = curl_exec($ch);
curl_close($ch);


echo $result;

Bruno

Re: Help: Where can I find a PHP sample to get my Token ?

Posted: Wed Oct 15, 2014 9:28 am
by Bruno
Solved !!!

This is my php code, It could help someone like me :)

Code: Select all

<?php
$url = 'https://ops.epo.org/3.1/auth/accesstoken';

$request_headers = array();
$request_headers[] = 'Content-Type: application/x-www-form-urlencoded'; 
$request_headers[] = 'Authorization: Basic QXQ1.........OenY2NA==';

$postdata  = "grant_type=client_credentials";

$myCurl = curl_init($url);
curl_setopt($myCurl, CURLOPT_HTTPHEADER, $request_headers);
// Pass the post parameters as a naked string
curl_setopt($myCurl, CURLOPT_POSTFIELDS, $postdata);
// Bypass https
curl_setopt($myCurl, CURLOPT_SSL_VERIFYPEER, false);

// Option to Return the Result, rather than just true/false
curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, true);
// Set the request type to POST
curl_setopt($myCurl, CURLOPT_POST, true);

$result = curl_exec($myCurl);
curl_close($myCurl);

print_r($result);

Re: Help: Where can I find a PHP sample to get my Token ?

Posted: Wed Oct 15, 2014 10:31 am
by EPO / OPS Support
Thanks Bruno, that's great: I am sure that will help someone else as well.

Kind regards,
OPS support

Re: Help: Where can I find a PHP sample to get my Token ?

Posted: Sun Nov 13, 2016 1:02 pm
by jpatent
Hi,
I get the error: 401Client identifier is required.
How do i correctly encode my key?

Thanks