2013-07-16 44 views
1

我嘗試在我的應用程序中登錄到vimeo上傳視頻,我在vimeo上創建的應用程序已獲批准。使用xAuth登錄vimeo

Upload Access

Approved for the following accounts: Your account

我用AFNetworking和AFOAuth1Client(https://github.com/AFNetworking/AFOAuth1Client),但也試過AFXAuthClient(https://github.com/romaonthego/AFXAuthClient)。

使用AFOAuth1Client用下面的代碼:

self.vimeoClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:vimeoBaseUrl] 
                 key:@"ClientIDHere" 
                secret:@"SecretHere"]; 
[self.vimeoClient postPath:@"/oauth/access_token" 
       parameters:[NSDictionary dictionaryWithObjectsAndKeys:@"client_auth",@"x_auth_mode",@"myEmail",@"x_auth_username",@"myPwd",@"x_auth_password",@"write",@"x_auth_permission", nil] 
        success:^(AFHTTPRequestOperation *operation, id responseObject) { 
    NSLog(@"..."); 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
    NSLog(@":%@", error.description); 
}]; 

我得到這個錯誤:

VimeoTest[49559:c07] :Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 401" UserInfo=0x75622d0 {NSLocalizedRecoverySuggestion=401 Unauthorized - Invalid signature - The oauth_signature passed was not valid., AFNetworkingOperationFailingURLRequestErrorKey=https://vimeo.com/oauth/access_token>, NSErrorFailingURLKey= https://vimeo.com/oauth/access_token , NSLocalizedDescription=Expected status code in (200-299), got 401, AFNetworkingOperationFailingURLResponseErrorKey=}

使用AFXAuthClient用下面的代碼:

//update begin 
AFXAuthToken *token = [[AFXAuthToken alloc] initWithKey:@"Access token from vimeo" secret:@"Access token secret"]; 
[self.vimeoXClient setToken:token]; 
//update end 

self.vimeoXClient = [[AFXAuthClient alloc] initWithBaseURL:[NSURL URLWithString:vimeoBaseUrl] 
key:@"ClientIDHere" 
secret:@"SecretHere"]; 
[self.vimeoXClient authorizeUsingXAuthWithAccessTokenPath:@"/oauth/access_token" 
              accessMethod:@"POST" 
               username: @"myEmail" 
               password: @"myPwd" 
                success:^(AFXAuthToken *accessToken) { 
                 NSLog(@"..."); 
                } 
                failure:^(NSError *error) { 
                 NSLog(@"error: %@", error.description); 

                }]; 

我得到這個錯誤:

更新代碼之後

錯誤(設置令牌):

2013-07-16 21:20:14.060 VimeoTest[52437:c07] error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 401" UserInfo=0x8b245a0 {NSLocalizedRecoverySuggestion=401 Unauthorized - Permission Denied - The oauth_token passed was either not valid or has expired., AFNetworkingOperationFailingURLRequestErrorKey=https://vimeo.com/oauth/access_token>, NSErrorFailingURLKey= https://vimeo.com/oauth/access_token , NSLocalizedDescription=Expected status code in (200-299), got 401, AFNetworkingOperationFailingURLResponseErrorKey=}

任何人有任何知道我做錯了嗎?

--- UPDATE ---

使用Runscope我發送以下參數

Accept: */* 
Accept-Encoding: gzip, deflate, compress 
Authorization: OAuth oauth_nonce="63129149524659229601374074093", oauth_timestamp="1374074093", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="MYCONSUMERKEYHERE", oauth_token="MYAPPTOKENHERE", oauth_callback="None", oauth_verifier="None", oauth_signature="lW%2BQYzwCcaDzSgoZUtvpSgLRSF4%3D" 
Connection: close 
Content-Length: 0 
Host: vimeo-com-bbmyq45awg44.runscope.net 
User-Agent: runscope/0.1 
X-Forwarded-For: 54.236.210.241 
X-Forwarded-Protocol: https 
X-Forwarded-Ssl: on 
X-Real-Ip: 54.236.210.241 
X_auth_mode: client_auth 
X_auth_password: MYPWDHERE 
X_auth_permission: write 
X_auth_username: MYUSERNAMEHERE 

我仍然得到

HEADERS 

Access-Control-Allow-Credentials: true 
Access-Control-Allow-Methods: GET, PUT, POST, PATCH, DELETE, OPTIONS, HEAD 
Access-Control-Allow-Origin: * 
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
Connection: close 
Content-Length: 104 
Content-Type: text/plain;charset=UTF-8 
Date: Wed, 17 Jul 2013 15:14:53 GMT 
Expires: Wed, 17 Jul 2013 03:14:53 GMT 
Runscope-Message-Id: 7bd9d07d-d043-4486-9a19-c3572997d3e4 
Server: Apache 
Vary: Accept-Encoding 
X-Dns-Prefetch-Control: on 
X-Powered-By: PHP/5.4.14 
BODY view raw 

401 Unauthorized - Permission Denied - The oauth_token passed was either not valid or has expired. 

我真的是同樣的反應不知道如果我錯過一些參數。需要oauth_verifier還是oauth_callback? 在我VIMEO應用程序的設置,我得到了以下內容:

Your Callback URL (edit) vimeoTest://success

+1

如果您成功接收到消息「傳遞的oauth_token無效或已過期」,那麼我認爲您正在正確發送您的請求。 您可以使用[Runscope](http://runscope.com)驗證所有標題和參數已成功設置。 如果正在發送所有正確的頭文件,Vimeo有能力驗證您使用的令牌。您可以通過他們的[幫助頁面](https://vimeo.com/help/contact)與他們聯繫。 – Dashron

回答

1

我也有類似的問題,我不得不把oauth_callback參數手動添加到該請求。如果您有桌面應用並且不會使用它,請將其設置爲oob。