php-soundcloud
php-soundcloud copied to clipboard
get('me') broken
Calling get('me') throws the following exception:
PHP NOTICE at /srv/www/megafone.net/public_html/protected/vendors/soundcloud/Services/Soundcloud.php (760): Array to string conversion
Actually I guess calling get('pretty_much_anything') would cause the same exception, as the problem seems to be that $this->_accessToken is an array.
I'm calling setAccessToken($token) where $token has been obtained by $client->accessToken($code).
If this is because accessToken() doesn't return a string, but an array, then
- the documentation at https://developers.soundcloud.com/docs/api/guide#authentication is utterly incomplete
- this library's methods are horribly designed if accessToken() doesn't return something that you're supposed to pass to setAccessToken (i.e. if setAccessToken() expects a string while accessToken() returns an array)
- setAccessToken should issue a sensible exception rather than blindly saving whatever you pass it into the private variable _accessToken
The error came from calling $accessToken=$client->accessToken() and then $client->setAccessToken($accessToken)
I have then figured out that the second call is unnecessary because accessToken() already sets the token, but see my three remarks in my previous comment.
Sorry, I was convinced that accessToken() was returning an array (well actually it was, but I was convinvced it was happening with no error) because
- removing the call to setAccessToken() fixed the issue (but this was probably together with adding the return_url parameter to the call to the constructor, as per the other bug)
- the accepted answer to this question in StackOverflow: http://stackoverflow.com/questions/12006580/soundcloud-api-access-token-oauth2/29594238#29594238 does
$soundcloud2->setAccessToken($accessToken["access_token"]);
which made me think that accessToken() returned an array whose element ['access_token'] would be a string. But now I seriously doubt after looking at the source code (and that answer in SO is completely screwed up anyway).
So, I think eventually I was simply suffering from issue #35 accessToken() was probably returning an array with an error response, and the unnecessary (but otherwise harmless) call to setAccessToken was hence passing it an array. I haven't double-checked, though.
My third remark is still valid though:
setAccessToken should issue a sensible exception rather than blindly saving whatever you pass it into the private variable _accessToken
I wanted to clarify my previous comment (now deleted), which I realised was unclear.
On success, the accessToken() method returns an array with the following keys:
access_token refresh_token expires_in scope
The setAccessToken() method requires the access token part only -- not the full array.
Your remark about setAccessToken() not raising an exception if an array is passed in is entirely valid, though, and will be added.