Paypal Permission API. GetBasicPersonalData in php

别等时光非礼了梦想. 提交于 2019-12-11 12:23:34

问题


I have received "tokenSecret" and "response token".

    $apiCred_user = "XXXX.com";
    $apiCred_pass = "XXXX";
    $accessToken = "XXXXXXXXXXXXXXKl8OlQ";
    $tokenSecret = "XXXXXXXXXXXXXsRg6ULs";
    $url = "https://api.sandbox.paypal.com/nvp";

    $auth = new AuthSignature();
    $response = $auth->genSign($apiCred_user ,$apiCred_pass ,$accessToken,$tokenSecret,'POST',$url);

    $authString =
    "token=".$accessToken.
    ",signature=".$response['oauth_signature'].
    ",timestamp=".$response['oauth_timestamp'];

Using this call, the signature is received. My doubt, The given url is used to generate the signautre. The call is correct?

To get result from "GetBasicPersonalData" , I have used this below code

$headers = array(
"X-PAYPAL-REQUEST-DATA-FORMAT:NV",
"X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T",
"X-PP-AUTHORIZATION: " .$authString,
"X-PAYPAL-RESPONSE-DATA-FORMAT:json");

$url_api = "https://svcs.paypal.com/Permissions/GetBasicPersonalData";
$post_array = array(
    "attributeList"=>array("attribute"=>"http://axschema.org/contact/email"),
    "requestEnvelope.errorLanguage"=>"en_US");
$curl_session =  curl_init();
    curl_setopt($curl_session, CURLOPT_URL,$url_api );
    curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl_session, CURLOPT_POST, 1);
    curl_setopt($curl_session, CURLOPT_POSTFIELDS, http_build_query($post_array));
    curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT,10); 
    curl_setopt($curl_session, CURLOPT_TIMEOUT, 10);                
    //curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 0);
    $response = json_decode(curl_exec($curl_session));
    curl_close($curl_session);

The response result is "Error"

{"responseEnvelope":

{"timestamp":"2015-02-05T09:26:53.053-08:00","ack":"Failure","correlationId":

"c74e091e7944e","build":"2210301"},"error":

[{"errorId":"560022","domain":"PLATFORM","subdomain":"Application","severity":"Error","category":"Application","message":"The X-PAYPAL-APPLICATION-ID header contains an invalid value","parameter":["X-PAYPAL-APPLICATION-ID"]}]}

Thanks ! 123456


回答1:


you forgot to ask for user's permission to get his personal data.

let's suppose you want to ask his permission to issue refunds, your request should look like this:

$data = array(
    'scope' => array(
        '0' => 'REFUND',
        '1' => 'ACCESS_BASIC_PERSONAL_DATA'
    ),
    'callback' => 'http://yoursite.com/page.php',  // The success page
    'requestEnvelope' => array(
        'errorLanguage' => 'en_US'    // Language used to display errors
    )
);

then you'll get the correct access token and token secret.

if you're still stuck, please ask for the complete code.



来源:https://stackoverflow.com/questions/28350137/paypal-permission-api-getbasicpersonaldata-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!