0

我有必要的身份验证详细信息,并且正在尝试执行 TransactionSearch。I keep getting an error: TIMESTAMP=2013%2d09%2d07T19%3a06%3a35Z&CORRELATIONID=b7af040415e92&ACK=Failure&VERSION=0%2e000000&BUILD=7507921&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Authentication%2fAuthorization%20Failed&L_LONGMESSAGE0=You%20do%20not%20have%20permissions%20to%20make% 20this%20API%20call&L_SEVERITYCODE0=错误

这是我的代码:

(timestamp, signature) = signaturegen.getAuthHeader(apiUser=settings.USERNAME, apiPass=settings.PASSWORD, accessTok=res2["token"], secTok=res2["tokenSecret"], httpMethod="POST", scriptURI="https://api-3t.sandbox.paypal.com/nvp")    
#the above operation is used to generate the timestamp and signature

headers = {"X-PAYPAL-AUTHORIZATION": "timestamp="+<timestamp>+",token="+<token>+",signature="+<signature>, "SUBJECT": settings.<API_USERNAME>}

data = {
"METHOD": "TransactionSearch",
"STARTDATE": "2012-01-01T05:38:48Z",
}
req= urllib2.Request("https://api-3t.sandbox.paypal.com/nvp", simplejson.dumps(data), headers)
res = urllib2.urlopen(req).read()
4

1 回答 1

0

我终于设法修复了代码,这是完整的版本:

import ast
import signaturegen
headers = {
    "X-PAYPAL-SECURITY-USERID": "xxxxxxxxx.xxxx.com",
    "X-PAYPAL-SECURITY-PASSWORD": "xxxxxxxx",
    "X-PAYPAL-SECURITY-SIGNATURE":  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
    "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T", #APP ID for sandbox

}


    headers = {
    "X-PAYPAL-SECURITY-USERID": settings.USERNAME,
    "X-PAYPAL-SECURITY-PASSWORD": settings.PASSWORD,
    "X-PAYPAL-SECURITY-SIGNATURE": settings.SIGNATURE,
    "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
    "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T"
}

    data = {"scope":"TRANSACTION_SEARCH", "callback":"http://www.example.com/success.html", "requestEnvelope": {"errorLanguage":"en_US"}}
    req = urllib2.Request("https://svcs.sandbox.paypal.com/Permissions/RequestPermissions/", simplejson.dumps(data), headers)    
    res = ast.literal_eval(urllib2.urlopen(req).read())
    token = res['token']
    red_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_grant-permission&request_token=%s" % token
   if red_url:
        return HttpResponseRedirect(red_url)
    token = "xxxxxxxxxxxxxxxxxx"
    verification = "xxxxxxxxxxxxxxxxxx"
    headers2 = {
    "X-PAYPAL-SECURITY-USERID": "xxxxxxxxxxxx",
    "X-PAYPAL-SECURITY-PASSWORD": "xxxxxxxxxxxxxxxx",
    "X-PAYPAL-SECURITY-SIGNATURE": "xxxxxxxxxxxxx",
    "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
    "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T",
}
    url = "https://svcs.sandbox.paypal.com/Permissions/GetAccessToken/"


    dat2 = {
        "requestEnvelope": {"errorLanguage":"en_US"}, 
        "token": "AAAAAAAYcambja9iJfUw", 
        "verifier": "iVUJ6c-6ZNk8M6Q9hkC12A"}
    req2 = urllib2.Request("https://svcs.sandbox.paypal.com/Permissions/GetAccessToken/", simplejson.dumps(dat2), headers2)
    res2 = ast.literal_eval(urllib2.urlopen(req2).read())


    (timestamp, signature) = signaturegen.getAuthHeader(apiUser="xxxxxxxxxxxx", apiPass="xxxxxxxxxxxxxxxx", accessTok=res2["token"], secTok=res2["tokenSecret"], httpMethod="POST", scriptURI="https://api-3t.sandbox.paypal.com/nvp")    

    ultimate = {"X-PAYPAL-AUTHORIZATION": "timestamp="+timestamp+",token="+res2["token"]+",signature="+signature, "SUBJECT": settings.USERNAME}

    da = {
        "METHOD": "TransactionSearch",
        "STARTDATE": "2012-01-01T05:38:48Z",
    }
    req3 = urllib2.Request("https://api-3t.sandbox.paypal.com/nvp", urllib.urlencode(da), ultimate)
    res3 = urllib2.urlopen(req3).read()
于 2013-10-06T21:17:59.133 回答