Rhomobile (Android 용)을 사용하여 Twitter에 상태 업데이트를 게시하고 있습니다. 이를 위해 Oauth 구현 단계에 따라 트위터에 로그인 할 수 있지만 로그인 후 HTTP 응답이 {"errors":[{"message":"Could not authenticate you","code":32}]}
일 때마다 상태 업데이트를 게시하려고합니다.Rhomobile : twitter에서 업데이트를 게시 할 수 없습니다.
다음은 상태 업데이트 게시 요청의 관련 코드입니다. 다음 추적
def get_auth_signature (url, url_param, secret)
signature = "POST&" + Rho::RhoSupport.url_encode(url).to_s +
"&" + Rho::RhoSupport.url_encode(url_param).to_s
key = $oauth_consumer_secret + "&" + secret
hmac = HMAC::SHA1.new(key)
hmac.update(signature)
$signature = Base64.encode64("#{hmac.digest}")
$signature = Rho::RhoSupport.url_encode("#{$signature.gsub(/\n/,'')}")
return $signature
end
파라미터 값은 :
@url_param 서명을 생성하기 전에 ---------
다음def post_to_twitter(comment)
$rnd = rand(36**32).to_s(36)
$post_status_url = "https://api.twitter.com/1.1/statuses/update.json"
$oauth_token1 = @account_set.tt_oauth_token
$oauth_token_secret1 = @account_set.tt_oauth_token_secret
@oauth_nonce = $rnd
@oauth_timestamp = Time.now.to_i.to_s
@http_port = System.get_property('rhodes_port')
@url_param = "oauth_consumer_key="+ $oauth_consumer_key + "&" +
"oauth_nonce=" + @oauth_nonce + "&" +
"oauth_signature_method=" + $oauth_signature_method + "&" +
"oauth_timestamp=" + @oauth_timestamp + "&" +
"oauth_token=" + $oauth_token1 + "&" +
"oauth_version="+ $oauth_version + "&" +
"status=" + Rho::RhoSupport.url_encode("Test")
$oauth_sign = get_auth_signature($post_status_url, @url_param, "")
@auth_header = "OAuth oauth_consumer_key="+ $oauth_consumer_key + ", " +
"oauth_nonce=" + @oauth_nonce + ", " +
"oauth_signature=" + $oauth_sign + ", " +
"oauth_signature_method=" + $oauth_signature_method + ", " +
"oauth_timestamp=" + @oauth_timestamp + ", " +
"oauth_token=" + $oauth_token1 + ", " +
"oauth_version="+ $oauth_version + ", " +
"status=" + Rho::RhoSupport.url_encode("Test")
postTTres = Rho::AsyncHttp.post(
:url => $post_status_url,
:headers =>{"Content-Type" => "application/x-www-form-urlencoded", "Authorization" => @auth_header }
)
p postTTres
end
서명 생성 함수는
oauth_consumer_key 2ChmEzWBe5Y9hMYODqA1IQ = & oauth_non CE = & iyb9502vspjnhj9orb87sriych16678b oauth_signature_method = HMAC-SHA1 oauth_timestamp = 1,380,117,614 & &의 oauth_token = 244,586,214-M6A2jMlR7vZiqwAMrfuSj7I7XFzFTRd4 6nV6aTLK oauth_version = 1.0 & & 상태 = Test`
서명을 생성하는 데에get_auth_signature()
@url_param
전달
. 생성 된 서명 URL 및 서명
서명 문자열 ----------
POST & HTTPS % 3A % 2F % 2Fapi.twitter.com % 2F1.1 % 2Fstatuses % 2Fupdate입니다 . JSON & oauth_consumer_key % 3D2ChmEzWBe5Y9hMYODqA1IQ % 26oauth_nonce % 3Diyb9502vspjnhj9orb87sriych16678b % 26oauth_signature_method % 3DHMAC-SHA1 %의 26oauth_timesta MP %의 3D1380117614 % 26oauth_token % 3D244586214-M6A2jMlR7vZiqwAMrfuSj7I7XFzFTRd46nV6aTLK % 26oauth_version % 3D1.0 % 26status % 3DTest "`
Base64로 문자열 - -----
gjdXuU3qoGNt90Q2dRhNM3IXaBI % 3D
는 heade로 모든 값을 전달 r에 https://api.twitter.com/1.1/statuses/update.json
에 대한 허가 및 {"errors":[{"message":"Could not authenticate you","code":32}]}
등
HTTP 응답을 얻었다.
또한 게시 매개 변수로 전달하려고 시도했습니다. 본문은 있지만 운이 없습니다.
postTTres = Rho::AsyncHttp.post(
:url => $post_status_url,
:headers =>{"Content-Type" => "application/x-www-form-urlencoded"},
:body => @url_param + "&oauth_signature=" + $oauth_sign
)
트위터 서버 타이밍과 시스템 타이밍을 확인했습니다.
트위터 계정에서 얻을 수있는 정적 oauth_token으로 시도했지만 역시 동일한 응답입니다.
제발 도와주세요.내가 누락 된 부분이나 잘못된 부분을 추적 할 수 없습니다.
감사
답장을 보내 주셔서 감사합니다. 사실, 나는 이미 언급 한 첫 번째 것을 시도했지만 동일한 대답을 얻었다. – user1113060
나는 게시물 2 자체를 전달할 때 서명의 입력 상태를 인코딩하고 인코딩을 제거한다고 말한만큼 옵션 2를 시도했다. 여전히 '당신을 인증 할 수 없습니다.'라는 오류 메시지가 나타납니다. 너에게 내가 시도해 보길 원하는 것, 또는 내가 놓칠지도 모른 무엇인가? – user1113060
업데이트 된 답변보기 행운을 빕니다. – Jos