Dropbox REST API thumbnails call - php

I'm writing a script, which fetches files from dropbox using it's REST API.
$this->oauth = new OAuth($consumer_key,$consumer_secret,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
$url = "https://api.dropbox.com/1/metadata/dropbox/";
$this->oauth->fetch($url);
Calls like these are working, so I get the authentication right. However the I can't get the thumbnails call working.
I have links like https://api-content.dropbox.com/1/thumbnails/dropbox/contact-support.jpg
That's an existing file, just fetched by the call above (which lists my files). My Dropbox app is in "full dropbox" mode, so "dropbox" as root should be OK too. I'm getting
"Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 403, expected HTTP/1.1 20X or a redirect)'..." errors constantly.
Any help would be appreciated, I'm starting to get frustrated by this.
Thanks a lot!

Related

Getting MIME-version of message results in "405 Method Not Allowed"-Error

My company runs a web-application that reads out a shared-mailbox and shows the content to the users. It was based on PHP-EWS so far. Since we're moving the mailbox into the Cloud, we have to migrate this application to MS-Graph.
I've already migrated the lion's share of the application, but now I encounter a problem when I try to get the MIME-version of a message.
Getting the processed version of the message is no problem at all.
The Request for this would be something like:
GET /users/{mailbox-id}/mailfolders/inbox/messages/{message-id}
According to the documentation I have to add "/$value" at the end of the "normal" request to get the mime-version of the message.
This works perfectly into Microsoft's Graph-Tester-Website. Within my application I can also request the MIME-version of an ATTACHED message without any problems (works with the same "/$value"-trick).
But if I request the MIME-Version of a (normal) NOT-ATTACHED message, I receive the following error:
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `GET https://graph.microsoft.com/v1.0/users/{mailbox-id}/mailfolders/inbox/messages/{message-id}/%24value`
resulted in a `405 Method Not Allowed` response: { "error": { "code": "ErrorInvalidRequest", "message": "The OData request is not supported.", "innerEr (truncated...) in D:\wwwroot\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113
Stack trace: #0 D:\wwwroot\vendor\guzzlehttp\guzzle\src\Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 D:\wwwroot\vendor\guzzlehttp\promises\src\Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 D:\wwwroot\vendor\guzzlehttp\promises\src\Promise.php(156): GuzzleHttp\Promise\Promise::callHand in D:\wwwroot\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113
I used the following code:
$graph = new Graph();
$graph->setAccessToken($tokenCache->getAccessToken());
/** #var $contentStream GuzzleHttp\Psr7\Stream */
$getMessageContentUrl = '/users/' . $mailbox . '/mailfolders/inbox/messages/' . $messageId.'/%24value';
try {
$contentStream = $graph->createRequest('GET', $getMessageContentUrl)
->setReturnType("GuzzleHttp\Psr7\Stream")
->execute();
} catch (GraphException $e) {
[...]
}
return $contentStream->getContents();
The same code works if I request the MIME-version of an attached message.
I thought at urlencoding-issues, so I tried "/$value" and "/%24value", same result.
I don't think that it is a permission problem. The OAUTH_SCOPES are
'openid profile offline_access User.Read Mail.Read Mail.Read.Shared Mail.ReadWrite Mail.ReadWrite.Shared Calendars.Read Calendars.Read.Shared'
So I think the account should have more than enough permissions to fulfill this task.
I have no idea, if I am doing something wrong or if it is a problem of the Graph-API or the Graph-PHP-SDK or the Guzzle-Http-Client.
I'm using the following versions:
"name": "microsoft/microsoft-graph",
"version": "1.11.0",
"name": "guzzlehttp/guzzle",
"version": "6.3.3",
"name": "guzzlehttp/psr7",
"version": "1.6.1",
I would be very glad if someone could help me or at least set me on the right track.
I found the solution. Had to replace
GET /users/{mailbox-id}/mailfolders/inbox/messages/{message-id}/$value
by
GET /users/{mailbox-id}/messages/{message-id}/$value
then it works. Kind of strange that other requests with "/mailfolders/inbox/" worked, but this one not. Whatever, as long as it works.
The Method Not Allowed Error means that the route you are requesting exists but not for the method you are using(GET). Try replacing GET method to POST like:
$contentStream = $graph->createRequest('POST', $getMessageContentUrl)
->setReturnType("GuzzleHttp\Psr7\Stream")
->execute();
Remember api's routes specifys methods alowed(GET, POST, PUT, PATCH, DELETE);

Yii2 OpenId Connect error - yii2-authclient returns 400 error "Token not provided" when I try to getUserAttributes()

I'm implementing OpenId Connect into my Yii2 app using the yii2-authclient library. I can login and exchange the code for a token with no problems. I've followed most of the code examples on the web and set a successCallback function that gets called once a user successfully logs in. It looks like this:
public function successCallback(ClientInterface $client)
{
$attributes = $client->getUserAttributes();
}
This code gets called, but calling getUserAttributes() results in the following error:
Exception – yii\authclient\InvalidResponseException
Request failed with code: 400, message:
{"error":"invalid_request","error_description":"Token not provided"}
The logs on the id server show a blank client and user, with an error of invalid_token.
I took a close look at the request I make and I see an access_token element. Any ideas what the problem might be? I can provide more information if necessary.
I figured it out. The problem was that the yii2-authclient library was sending the token as a GET parameter and the ID server was expecting it as a POST param. I upgraded the yii2-authclient library and that solved the problem since a recent change sends the parameter as POST instead of GET.

Can't post new track via PHP Soundcloud API

I'm in a bit of a pickle here. I developped a Wordpress plugin that helps my site publish sounds to soundcloud directly from the WP back-office. The site has been live for about a year, and I have had no problems until now.
When uploading a track, I get a 'Fatal error: Uncaught exception 'Services_Soundcloud_Invalid_Http_Response_Code_Exception' with message 'The requested URL responded with HTTP code 422.'
I checked if nothing on my code had changed, and it hasn't, the request seems properly formed. Here is the bit of code:
$soundcloud->setAccessToken($_POST['access_token']);
$mytrack = array(
'track[title]' => $_POST["audioname"],
'track[asset_data]' => $_FILES["audiofile"]["tmp_name"]
);
$track = json_decode($soundcloud->post('tracks', $mytrack));
Any idea what could be wrong? I have a Pro Unlimited account, so I can't have reached a quota, can I? Other functions used through the API work properly...
If you are getting a 422 http code. That's 'Unprocessable entity' error acording to the docs. What it probably mean is that you data structure is wrong.
I don't know the php library you're using but I invite you to try out my own opensource library. https://github.com/njasm/soundcloud . Check the readme. You have an example on how to upload tracks.

OAuthException: An unexpected error has occurred - after changing app namespace

we had a working facebook app with an own action that has been reviewed and been approved by facebook. Everything worked fine.
After changing the namespace and the title of the app, we now get an an error when sending the action via php sdk, althought all the action is still marked as approved and live.
$response = $facebook->api(
'me/myapp:create',
'POST', array('custom_object' => "http://www.myapp.com/metatags.php") );
This is the error we receive:
OAuthException: An unexpected error has occurred. Please retry your request later.
We've' already checked if the access token is vaild, it is!
Is it possible that facebook needs to re-approve custom actions after changing the namespace? Or does it need some time until it works again?
I dealt with this today, however my experience was in JavaScript, so I don't have relevant code to provide, you should be able to apply the same theory!
It seems that the error only happens once per access request - if you try to post again immediately after, it will usually be accepted by facebook with no error. Since the error code returned for unknown error is always the same, you can simply catch the error code from the response object and run the function again if it matches.

LinkedIn with Pecl OAuth: "got a 400, expected HTTP/1.1 20X or a redirect"

I have Pecl OAuth with PHP5 on a Debian box and I try to authenticate to LinkedIn. When calling;
OAuth->getAccessToken('https://api.lin...')\n#1
I get;
PHP Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 400, expected HTTP/1.1 20X or a redirect)'
I have tried it from scratch and I have tried the PHP API wrappers that are available and (ofcourse, because they use OAuth Pecl ext) have all the same problem.
I read somewhere it might be the timestamp on the server, but I synched that up with ntpdate; it does that quite often now, so the offset with the timeservers is almost 0.
I tried this class first; http://www.linkedphp.com/2009/11/26/first-release-classes-to-connect-with-php-to-linkedin-api/, someone in the comments has the same problem, however the creator of the class says 'do you get a login screen'; I don't, I get a 'Grant or Deny' screen once, after that a blank screen and the above error in my logs.
What else can it be?
Thanks
Yep, confirmed. Timestamp IS the problem.
Make sure your server date/time is in sync with the rest of the world (i use Timeserver hostnames or addresses: ntp.cpsc.ucalgary.ca )
nb: I'm starting to think that this whole oauth thing is a bad , complicated thing :)
You should post your code.
Besides the timestamp issues, missing callbacl URL in the request can also cause this error.
Try using the format:
$access_token_info = $oauth->getAccessToken($accesstokenurl, "", $token);
where $token is the 5 digit confirmation code

Categories