简体   繁体   中英

QQ OAuth error code

I'm trying to use the QQ (Huge Chinese social network similar to ICQ) API which uses OAuth. I'm reasonably familiar with OAuth, but I can only read Chinese via Google Translate.

I use Rails 3.0.7 and follow the instructions in the oauth gem documentation .

According to the QQ documentation their APP ID corresponds to oauth_consumer_key and their APP KEY is the oauth consumer secret. They also specify which URL's to use. So I do the following in the console:

@consumer=OAuth::Consumer.new("APP ID", "APP SECRET",{:site =>
"http://openapi.qzone.qq.com", :request_token_path=>"/oauth/qzoneoauth_request_token", 
:authorize_path => "/oauth/qzoneoauth_authorize", :access_token_path => 
"/get_access_token.php"} )

That returns:

#<OAuth::Consumer:0x0000010283f6a0 @key="APP ID", @secret="APP SECRET", 
@options={:signature_method=>"HMAC-SHA1", 
:request_token_path=>"/oauth/qzoneoauth_request_token", 
:authorize_path=>"/oauth/qzoneoauth_authorize", 
:access_token_path=>"/get_access_token.php", :proxy=>nil, :scheme=>:header, 
:http_method=>:post, :oauth_version=>"1.0", :site=>"http://openapi.qzone.qq.com"}> 

Now it's time to get a request token from the server:

@request_token=@consumer.get_request_token

Unfortunately this returns an error code: 12005 meaning invalid url (thanks @timon-vonk). But what's wrong with it and how do I debug this? Here's a few more details about the request, obtained with net-http-spy :

@request_token=@consumer.get_request_token(
:oauth_callback => "http://ishiyou.com/qq")          
opening connection to openapi.qzone.qq.com...opened
<- "GET /oauth/qzoneoauth_request_token HTTP/1.1\r\nAccept: */*\r\nUser-Agent: 
OAuth gem v0.4.4\r\nAuthorization: OAuth 
oauth_callback=\"http%3A%2F%2Fishiyou.com%2Fqq\", 
oauth_consumer_key=\"******\", 
oauth_nonce=\"gpv3iaYb7K3tExGxxnW5bjkyvU6ms3EuL9roLwgxs4\", 
oauth_signature=\"3tgryVqRFjxoXSxnYTO%2FXuRNAU4%3D\", 
oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1306933000\", 
oauth_version=\"1.0\"\r\nConnection: close\r\nHost: openapi.qzone.qq.com\r\n\r\n"
-> "HTTP/1.1 200 OK\r\n"
-> "Connection: close\r\n"
-> "Server: QZHTTP-2.13\r\n"
-> "Date: Wed, 01 Jun 2011 12:56:42 GMT\r\n"
-> "Content-Length: 17\r\n"
-> "Content-type: text/html\r\n"
-> "Cache-Control: no-cache\r\n"
-> "\r\n"
reading 17 bytes...
-> "error_code=12005\n"
read 17 bytes
Conn close

A 12005 error is usually an invalid URL.

Invalid in the sense that the URL generated is not valid, not non existent. Check what URL is generated. Also, its possible that QQ just parses the request wrong and doesn't send a 404 but a 12005 for some reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM