2016-03-09 38 views
2

我有一個媒體API(Delegator應用程序),我試圖讓第三方應用程序(消費者應用程序)的用戶通過我的API代表用戶(用戶)推特視頻, ,所以我正在執行Oauth Echo。我能夠完成第一步,驗證用戶的憑據,所以我知道我的憑證是有效的;然而,當我去初始化上傳時,我得到一個「無法驗證你」的錯誤。在分塊的媒體上傳的文檔,我注意到了這部分,但它是我不清楚如何適用於通過OAuth回聲進行chunked media upload用Oauth Echo上傳分塊的視頻到推特

「因爲該方法使用多POST,OAuth是處理一個小 不同POST或 計算OAuth簽名基礎字符串或簽名時不使用查詢字符串參數,只使用 oauth_ *參數。「

下面是我的要求輸出的調試:

opening connection to upload.twitter.com:443... opened starting SSL for upload.twitter.com:443... SSL established <- "POST /1.1/media/upload.json?command=INIT&media_type=video%2Fmp4&total_bytes=2000 HTTP/1.1\r\nAuthorization: OAuth oauth_consumer_key=\"XXXXXXXXXXXXXXXXX\", oauth_nonce=\"XXXXXXXXXXXXXXXXX\", oauth_signature=\"XXXXXXXXXXXXXXXXX\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1457492349\", oauth_token=\"XXXXXXXXXXXXXXXXX\", oauth_version=\"1.0\"\r\nConnection: close\r\nHost: upload.twitter.com\r\nContent-Length: 0\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n" <- "" 
-> "HTTP/1.1 401 Authorization Required\r\n" 
-> "connection: close\r\n" 
-> "content-length: 64\r\n" 
-> "content-type: application/json; charset=utf-8\r\n" 
-> "date: Wed, 09 Mar 2016 03:10:23 GMT\r\n" 
-> "server: tsa_a\r\n" 
-> "set-cookie: guest_id=v1%3A145749302339262531; Domain=.twitter.com; Path=/; Expires=Fri, 09-Mar-2018 03:10:23 UTC\r\n" 
-> "strict-transport-security: max-age=631138519\r\n" 
-> "vary: Origin\r\n" 
-> "x-connection-hash: 6a4b3c223cca493550d30c3fed750df1\r\n" 
-> "x-frame-options: SAMEORIGIN\r\n" 
-> "x-response-time: 7\r\n" 
-> "x-xss-protection: 1; mode=block\r\n" 
-> "\r\n" reading 64 bytes... 
-> "" 
-> "{\"errors\":[{\"code\":32,\"message\":\"Could not authenticate you.\"}]}" read 64 bytes Conn close 
=> #[{"code"=>32, "message"=>"Could not authenticate you."}]}, @response=#, @headers={"connection"=>["close"], "content-length"=>["64"], "content-type"=>["application/json; charset=utf-8"], "date"=>["Wed, 09 Mar 2016 03:10:23 GMT"], "server"=>["tsa_a"], "set-cookie"=>["guest_id=v1%3A145749302339262531; Domain=.twitter.com; Path=/; Expires=Fri, 09-Mar-2018 03:10:23 UTC"], "strict-transport-security"=>["max-age=631138519"], "vary"=>["Origin"], "x-connection-hash"=>["6a4b3c223cca493550d30c3fed750df1"], "x-frame-options"=>["SAMEORIGIN"], "x-response-time"=>["7"], "x-xss-protection"=>["1; mode=block"]}> 

我正在使用HTTParty寶石的HTTP請求。下面是他們的樣子:

#IRL I'm getting the following two vars from the user, but for sake of demonstration this is more or less what they'll be 
x_auth_service_provider = 'https://api.twitter.com/1.1/account/verify_credentials.json' 
x_verify_credentials_authorization = 'OAuth oauth_consumer_key="XXXX", oauth_nonce="XXXX", oauth_signature="XXXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1457473883", oauth_token="XXXX", oauth_version="1.0"' 

response = HTTParty.get(x_auth_service_provider, 
    :headers => {"Authorization" => x_verify_credentials_authorization}) 

if response.code == 200 
    init = HTTParty.post('https://upload.twitter.com/1.1/media/upload.json', 
    :headers => {"Authorization" => x_verify_credentials_authorization}, 
    :body => {'command' => 'INIT', 'media_type'=> 'video/mp4', 'total_bytes' => '2000'}, 
    :debug_output => $stdout) 
end 

回答

1

我曾試圖彌補在儀表板相同的請求,到那裏我去:

  1. https://apps.twitter.com/
  2. 點擊了我的應用程序
  3. 被點擊「測試OAuth「按鈕(右上)

第一次我和你有同樣的錯誤,但我注意到了這個:

重要提示:這隻會在幾分鐘內有效。

我試着重新生成OAuth簽名,之後請求進行得很順利。那麼,也許你的授權密鑰也過期了?