Re: [rdio-api] Need help with OAuth 2.0 and PHP

88 views
Skip to first unread message

Devin Sevilla

unread,
Jun 15, 2015, 5:28:25 PM6/15/15
to rdio...@googlegroups.com
Hi Roland!

I answered a similar question on StackOverflow, but the question
appears to have been deleted. I'll repeat the answer here.

You are using two different methods to pass the access token[1]. You
can use one or the other. You need to make sure you're making a POST
request. You'll also need to pass the method name and parameters in
the body of the request.

To do this with PHP: set the `CURLOPT_POSTFIELDS` option using the
`curl_setopt` method[2]. The value of the `CURLOPT_POSTFIELDS` option
will be an array (map) containing the method name and parameters. The
array should look something like:

array(
'method' => 'get',
'keys'=> 'r139688'
)

[1]: http://www.rdio.com/developers/docs/web-service/oauth2/overview/ref-using-an-access-token
[2]: http://php.net/manual/en/function.curl-setopt.php

--
Devin Sevilla
API Engineer, Rdio Inc.
http://rdio.com/people/devin_s/

On Sun, Jun 14, 2015 at 1:53 PM, Roland Beck <oberas...@gmail.com> wrote:
> Hello,
>
> sorry, I´m very new to OAuth 2.0.
>
> I want to make a little php script...
>
> I have no problems to get an access token. But I dont get it, what I have to
> do with the access token.
>
> Can someone give my an example, how I can use the access token to make an
> api call? (for example to get my playlists or username) .
>
> The access token is saved in $access_key.
>
> I tried this little test - but not nothing happend:
>
>
> $curl = curl_init();
>
> curl_setopt($curl, CURLOPT_URL,
> 'https://services.rdio.com/api/1/?access_token='.$access_key);
> curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer
> '.$access_key'));
> $resp = curl_exec($curl);
> curl_close($curl);
>
>
> // Print response or handle error
> if($resp){ echo $resp; }
> else{ die('Error: "' . curl_error($curl)); }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Rdio API" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rdio-api+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rdio-api/25405cfc-e352-4d6c-bd91-f340dfc5052c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ying Zhang

unread,
Jun 17, 2015, 4:05:52 AM6/17/15
to rdio...@googlegroups.com
Hey guys, I made a quick and dirty Rdio class that supports OAuth 2.0 and wraps the web service calls. It's here: https://github.com/ying17/rdiolib-php

Roland, here is a relevant snippet that should help with what you're trying to do:

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-type: application/x-www-form-urlencoded',
'Authorization: Bearer '.$access_token
]);
$result = curl_exec($ch);

Where $params is an array containing the method you're calling and relevant parameters. For example:

$params = ['method'=>'currentUser'];

Good luck,
Ying
Reply all
Reply to author
Forward
0 new messages