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

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 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛