Xero PHP API,收到错误

时间:2017-12-20 04:56:15

标签: xero-api

我正在关注的步骤。

  1. 我将authenticate参数作为1发送到public.php文件并接收oauth_token和oauth_token_secret。
  2. http://localhost/XeroOAuth-PHP-master/public.php?authenticate=1

    此阶段会话生成如下

    阵 (     [oauth] =>排列         (             [oauth_token] => XXX             [oauth_token_secret] => XXX             [oauth_callback_confirmed] =>真正         )

    1. 下一步,我正在调用此网址http://localhost/XeroOAuth-PHP-master/public.php?oauth_verifier=1&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC
    2. 在此阶段,它会抛出错误,即permit_denied。

      错误:oauth_problem = permission_denied& oauth_problem_advice =%20consumer%20was%20denied%20access%20to%20this%20resource。

      以下是我在页面中收到的整个错误格式。

      XeroOAuth对象 (     [_xero_defaults] =>排列         (             [xero_url] => https://api.xero.com/             [site] => https://api.xero.com             [authorize_url] => https://api.xero.com/oauth/Authorize             [signature_method] => HMAC-SHA1         )

      [_xero_consumer_options] => Array
          (
              [request_token_path] => oauth/RequestToken
              [access_token_path] => oauth/AccessToken
              [authorize_path] => oauth/Authorize
          )
      
      [_action] => 
      [_nonce_chars] => 
      [params] => Array
          (
          )
      
      [headers] => Array
          (
              [Accept] => application/xml
              [Content-Length] => 0
              [Expect] => 
          )
      
      [auto_fixed_time] => 
      [buffer] => 
      [request_params] => Array
          (
          )
      
      [_xero_curl_options] => Array
          (
              [curl_connecttimeout] => 30
              [curl_timeout] => 20
              [curl_ssl_verifypeer] => 2
              [curl_cainfo] => C:\xampp\htdocs\XeroOAuth-PHP-master/certs/ca-bundle.crt
              [curl_followlocation] => 
              [curl_ssl_verifyhost] => 2
              [curl_proxy] => 
              [curl_proxyuserpwd] => 
              [curl_encoding] => 
              [curl_verbose] => 1
          )
      
      [config] => Array
          (
              [xero_url] => https://api.xero.com/
              [site] => https://api.xero.com
              [authorize_url] => https://api.xero.com/oauth/Authorize
              [signature_method] => HMAC-SHA1
              [request_token_path] => oauth/RequestToken
              [access_token_path] => oauth/AccessToken
              [authorize_path] => oauth/Authorize
              [curl_connecttimeout] => 30
              [curl_timeout] => 20
              [curl_ssl_verifypeer] => 2
              [curl_cainfo] => C:\xampp\htdocs\XeroOAuth-PHP-master/certs/ca-bundle.crt
              [curl_followlocation] => 
              [curl_ssl_verifyhost] => 2
              [curl_proxy] => 
              [curl_proxyuserpwd] => 
              [curl_encoding] => 
              [curl_verbose] => 1
              [application_type] => Public
              [oauth_callback] => localhost
              [user_agent] => Xero-OAuth-PHP Public
              [consumer_key] => XXX
              [shared_secret] => XXX
              [core_version] => 2.0
              [payroll_version] => 1.0
              [file_version] => 1.0
              [access_token] => XXX
              [access_token_secret] => XXX
              [host] => https://api.xero.com/oauth/
              [multipart] => 
          )
      
      [method] => GET
      [url] => https://api.xero.com/oauth/AccessToken
      [sign] => Array
          (
              [parameters] => Array
                  (
                      [oauth_consumer_key] => YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7
                      [oauth_nonce] => Ubrb
                      [oauth_signature_method] => HMAC-SHA1
                      [oauth_timestamp] => 1504002299
                      [oauth_token] => 3CHDO7HFISTMVJXDX7IIPMRJUZH2FC
                      [oauth_verifier] => 1
                      [oauth_version] => 1.0
                      [oauth_signature] => o9ucXeTTvA04tQgLTBX5AuMoX2Y=
                  )
      
              [signature] => o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D
              [signed_url] => https://api.xero.com/oauth/AccessToken?oauth_consumer_key=YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7&oauth_nonce=Ubrb&oauth_signature=o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1504002299&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC&oauth_verifier=1&oauth_version=1.0
              [header] => OAuth oauth_consumer_key="YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7", oauth_nonce="Ubrb", oauth_signature="o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1504002299", oauth_token="3CHDO7HFISTMVJXDX7IIPMRJUZH2FC", oauth_verifier="1", oauth_version="1.0"
              [sbs] => GET&https%3A%2F%2Fapi.xero.com%2Foauth%2FAccessToken&oauth_consumer_key%3DYDOVURHNHW7RIHJ384ZYJ7TMVQT8W7%26oauth_nonce%3DUbrb%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1504002299%26oauth_token%3D3CHDO7HFISTMVJXDX7IIPMRJUZH2FC%26oauth_verifier%3D1%26oauth_version%3D1.0
          )
      
      [format] => xml
      [response] => Array
          (
              [headers] => Array
                  (
                      [cache_control] => private
                      [content_type] => text/html; charset=utf-8
                      [date] => Tue, 29 Aug 2017 10:25:01 GMT
                      [strict_transport_security] => max-age=31536000
                      [www_authenticate] => OAuth Realm="10.144.115.64"
                      [content_length] => 115
                      [connection] => keep-alive
                  )
      
              [code] => 401
              [response] => oauth_problem=permission_denied&oauth_problem_advice=The%20consumer%20was%20denied%20access%20to%20this%20resource.
              [info] => Array
                  (
                      [url] => https://api.xero.com/oauth/AccessToken?oauth_consumer_key=YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7&oauth_nonce=Ubrb&oauth_signature=o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1504002299&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC&oauth_verifier=1&oauth_version=1.0
                      [content_type] => text/html; charset=utf-8
                      [http_code] => 401
                      [header_size] => 267
                      [request_size] => 418
                      [filetime] => -1
                      [ssl_verify_result] => 0
                      [redirect_count] => 0
                      [total_time] => 1.438
                      [namelookup_time] => 0
                      [connect_time] => 0.328
                      [pretransfer_time] => 1.016
                      [size_upload] => 0
                      [size_download] => 115
                      [speed_download] => 79
                      [speed_upload] => 0
                      [download_content_length] => 115
                      [upload_content_length] => -1
                      [starttransfer_time] => 1.438
                      [redirect_time] => 0
                      [redirect_url] => 
                      [primary_ip] => 54.209.35.242
                      [certinfo] => Array
                          (
                          )
      
                      [primary_port] => 443
                      [local_ip] => 192.168.1.35
                      [local_port] => 60675
                      [request_header] => GET /oauth/AccessToken?oauth_consumer_key=YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7&oauth_nonce=Ubrb&oauth_signature=o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1504002299&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC&oauth_verifier=1&oauth_version=1.0 HTTP/1.1
      

      主持人:api.xero.com User-Agent:Xero-OAuth-PHP Public Accept-Encoding:deflate,gzip 接受:application / xml 内容长度:0

                  )
      
              [format] => xml
          )
      

1 个答案:

答案 0 :(得分:0)

如果在访问令牌尚未获得组织授权时尝试交换访问令牌的请求令牌,则会返回此错误。

应用程序流程中应该有一个步骤,将用户重定向到https://api.xero.com/oauth/Authorize?oauth_token=[OAUTH_TOKEN_HERE] - 一旦Xero用户选择了他们提供访问权限的组织并且给予了确定,您的第二次调用就应该工作