Angular dropbox api / token endpoint返回無效請求

[英]Angular dropbox api /token endpoint returns invalid request


I'm trying to build a connection to dropbo using angular.js. For this i have the following piece of code to do a request to https://api.dropboxapi.com/1/oauth2/token .

我正在嘗試使用angular.js建立與dropbo的連接。為此,我有以下代碼來請求https://api.dropboxapi.com/1/oauth2/token。

The code is obtained in the url after the user clicks-through to the verification url of dropbox and back. $scope.accessUrl = 'https://www.dropbox.com/1/oauth2/authorize?client_id=szj63bffo9rp5v7&response_type=' + $scope.response_type + '&redirect_uri=' + $scope.redirect_uri; This seems to work, since a code is returned via get and it is available in function below.

用戶點擊后到dropbox的驗證網址並返回后,在網址中獲取代碼。 $ scope.accessUrl ='https://www.dropbox.com/1/oauth2/authorize?client_id=szj63bffo9rp5v7&response_type='+ $ scope.response_type +'&redirect_uri ='+ $ scope.redirect_uri;這似乎有效,因為代碼是通過get返回的,它在下面的函數中可用。

            $http({
                method: 'POST',
                grant_type: 'authorization_code',
                code: <<<<token>>>>,
                client_id: '<<<<mydropbox.key>>>>',
                client_secret: '<<<<mydropbox.secret>>>>',
                redirect_uri: "http://localhost:8080",

                contentType: "application/json",
                url: "https://api.dropboxapi.com/1/oauth2/token"
            })

However, I've tried for a while to get this working and it I'm stuck. I'm not sure what is causing this error but it is always the following response: error:"invalid_request" error_description:"No auth function available for given request"

但是,我已經嘗試了一段時間才能使這個工作,而且我被卡住了。我不確定導致此錯誤的是什么,但始終是以下響應:錯誤:“invalid_request”error_description:“沒有可用於給定請求的auth功能”

And the HTTP status code is always 400 (bad request).

並且HTTP狀態代碼始終為400(錯誤請求)。

I'm new to angular. A similar $http request has worked for a different endpoint. For this endpoint I put Bearer: <<<< authorization key that should be returned from broken function above >>>> in the url and a path in data{} of the body.

我是棱角分明的新手。類似的$ http請求適用於不同的端點。對於這個端點,我把Bearer:<<< <授權密鑰應該從上面的破壞函數返回> >>>在url中,以及一個路徑在body {}中。

If anyone knows what I'm doing wrong, of which I'm guessing it's likely a silly mistake, I'd love some help.

如果有人知道我做錯了什么,我猜它可能是一個愚蠢的錯誤,我會喜歡一些幫助。

2 个解决方案

#1


0  

You should pass required data in data property as dictionary. https://docs.angularjs.org/api/ng/service/$http#usage

您應該將data屬性中的所需數據作為字典傳遞。 https://docs.angularjs.org/api/ng/service/$http#usage

If you need to pass some data in headers, use headers property. https://docs.angularjs.org/api/ng/service/$http#setting-http-headers

如果需要在標頭中傳遞一些數據,請使用headers屬性。 https://docs.angularjs.org/api/ng/service/$http#setting-http-headers

        $http({
            method: 'GET',
            data: {
                 grant_type: 'authorization_code',
                 code: <<<<token>>>>,
                 client_id: '<<<<mydropbox.key>>>>',
                 client_secret: '<<<<mydropbox.secret>>>>',
                 redirect_uri: "http://localhost:8080"
            },
            contentType: "application/json",
            url: "https://api.dropboxapi.com/1/oauth2/token"
        })

#2


0  

I finally found the answer. The API documentation of dropbox didn't notice me of the fact I had to send contentType: "application/x-www-form-urlencoded".

我終於找到了答案。 dropbox的API文檔沒有注意到我必須發送contentType的事實:“application / x-www-form-urlencoded”。

They noticed that in general you should send json so I assumed this was true unless mentioned otherwise.

他們注意到一般情況下你應該發送json所以我認為這是真的,除非另有說明。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/08/16/72997d12e651fed56b0b3a6e205d0660.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com