dongxun8189 2013-06-17 06:11
浏览 54
已采纳

tmhOAuth twitter api 1.0到1.1获取错误400错误认证

trying to use new tmhOAuth and replaced my old one then set version to 1.1.

After that i edited code in my php and changed user_token to token and user_secret to secret.

Page goes to twitter login then after redirecting to website then user this code $code = $tmhOAuth->user_request(array('url' => $tmhOAuth->url('1.1/account/verify_credentials')));

It gets error getting error bad authentication didn't happen in 1.0 version before. here is the twitter response:

Error: {"errors":[{"message":"Bad Authentication data","code":215}]}
tmhOAuth Object
(
[response] => Array
(
[raw] => HTTP/1.1 400 Bad Request
content-type: application/json; charset=utf-8
date: Mon, 17 Jun 2013 04:18:33 UTC
server: tfe
set-cookie: guest_id=v1%3A137144271317108052; Domain=.twitter.com; Path=/; Expires=Wed, 17-Jun-2015 04:18:33 UTC
strict-transport-security: max-age=631138519
Transfer-Encoding: chunked
Content-Encoding: gzip

{"errors":[{"message":"Bad Authentication data","code":215}]}
[headers] => Array
(
[HTTP/1.1 400 Bad Request] =>
[content-type] => application/json; charset=utf-8
[date] => Mon, 17 Jun 2013 04:18:33 UTC
[server] => tfe
[set-cookie] => guest_id=v1%3A137144271317108052; Domain=.twitter.com; Path=/; Expires=Wed, 17-Jun-2015 04:18:33 UTC
[strict-transport-security] => max-age=631138519
[Transfer-Encoding] => chunked
[Content-Encoding] => gzip
[] =>
)

        [code] => 400
        [response] => {"errors":[{"message":"Bad Authentication data","code":215}]}
        [info] => Array
            (
                [url] => https://api.twitter.com/1.1/account/verify_credentials.json
                [content_type] => application/json; charset=utf-8
                [http_code] => 400
                [header_size] => 337
                [request_size] => 442
                [filetime] => -1
                [ssl_verify_result] => 0
                [redirect_count] => 0
                [total_time] => 3.135
                [namelookup_time] => 0.093
                [connect_time] => 0.53
                [pretransfer_time] => 2.621
                [size_upload] => 0
                [size_download] => 86
                [speed_download] => 27
                [speed_upload] => 0
                [download_content_length] => -1
                [upload_content_length] => 0
                [starttransfer_time] => 3.135
                [redirect_time] => 0
                [certinfo] => Array
                    (
                    )

                [primary_ip] => 199.59.150.9
                [primary_port] => 443
                [local_ip] => 192.168.20.103
                [local_port] => 52016
                [redirect_url] => 
                [request_header] => GET /1.1/account/verify_credentials.json HTTP/1.1

User-Agent: tmhOAuth 0.8.2+SSL - //github.com/themattharris/tmhOAuth
Host: api.twitter.com
Accept: /
Accept-Encoding: deflate, gzip
Authorization: OAuth oauth_consumer_key="whXGehzgX72Jnz6VOwXVBg", oauth_nonce="c3c2f3adde1b18704f267ff8fbffb567", oauth_signature="IeSgCdyRjgJXSvJbfohJxRXGv6Q%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1371442710", oauth_version="1.1"

            )

        [error] => 
        [errno] => 0
    )

[buffer] => 
[config] => Array
    (
        [user_agent] => tmhOAuth 0.8.2+SSL - //github.com/themattharris/tmhOAuth
        [host] => api.twitter.com
        [consumer_key] => whXGehzgX72Jnz6VOwXVBg
        [consumer_secret] => iGXrfjiJ9iyuqMYz1Ild6KHhnpJ9xhqfq7NoiEdtZU
        [token] => 
        [secret] => 
        [bearer] => 
        [oauth_version] => 1.1
        [oauth_signature_method] => HMAC-SHA1
        [curl_connecttimeout] => 30
        [curl_timeout] => 10
        [curl_ssl_verifyhost] => 2
        [curl_ssl_verifypeer] => 1
        [use_ssl] => 1
        [curl_cainfo] => D:\xampp\htdocs\photolivedesktop\application\libraries\twitter\cacert.pem
        [curl_capath] => D:\xampp\htdocs\photolivedesktop\application\libraries\twitter
        [curl_followlocation] => 
        [curl_proxy] => 
        [curl_proxyuserpwd] => 
        [curl_encoding] => 
        [is_streaming] => 
        [streaming_eol] => 

        [streaming_metrics_interval] => 10
        [as_header] => 1
        [force_nonce] => 
        [force_timestamp] => 
    )

[request_settings] => Array
    (
        [params] => Array
            (
            )

        [headers] => Array
            (
                [Authorization] => OAuth oauth_consumer_key="whXGehzgX72Jnz6VOwXVBg", oauth_nonce="c3c2f3adde1b18704f267ff8fbffb567", oauth_signature="IeSgCdyRjgJXSvJbfohJxRXGv6Q%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1371442710", oauth_version="1.1"
            )

        [with_user] => 1
        [multipart] => 
        [method] => GET
        [without_bearer] => 
        [url] => https://api.twitter.com/1.1/account/verify_credentials.json
        [oauth1_params] => Array
            (
                [oauth_consumer_key] => whXGehzgX72Jnz6VOwXVBg
                [oauth_nonce] => c3c2f3adde1b18704f267ff8fbffb567
                [oauth_signature] => IeSgCdyRjgJXSvJbfohJxRXGv6Q%3D
                [oauth_signature_method] => HMAC-SHA1
                [oauth_timestamp] => 1371442710
                [oauth_version] => 1.1
            )

        [prepared_params] => Array
            (
            )

        [basestring_params] => oauth_consumer_key=whXGehzgX72Jnz6VOwXVBg&oauth_nonce=c3c2f3adde1b18704f267ff8fbffb567&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1371442710&oauth_version=1.1
        [basestring] => GET&https%3A%2F%2Fapi.twitter.com%2F1.1%2Faccount%2Fverify_credentials.json&oauth_consumer_key%3DwhXGehzgX72Jnz6VOwXVBg%26oauth_nonce%3Dc3c2f3adde1b18704f267ff8fbffb567%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1371442710%26oauth_version%3D1.1
        [signing_key] => iGXrfjiJ9iyuqMYz1Ild6KHhnpJ9xhqfq7NoiEdtZU&
    )

)

Can someone tell me what I am doing wrong?

Thanks

  • 写回答

1条回答 默认 最新

  • douzhi9939 2013-06-17 09:41
    关注

    Not having used this library before I had no trouble with the following:

    <?php
    require 'tmhOAuth.php';
    
    $client= new tmhOAuth( array(
      'consumer_key'    => '<my app key>',
      'consumer_secret' => '<my app secret>',
      'token'           => '<my access token>',
      'secret'          => '<my access secret>',
    ) );
    
    $code = $client->user_request( $client->url('1.1/account/verify_credentials') );
    var_dump( $code );
    // gives: (int) 200
    

    Check your credentials and perhaps you can post the code you're using in full.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?