无法使用 Rest API 下载与 Paypal 争议相关的附件

问题描述 投票:0回答:1

无法通过Rest Api下载争议相关附件

生成的访问令牌具有以下所有范围: scopes

我可以使用此 api 端点获取争议: https://api-m.sandbox.paypal.com/v1/customer/disputes/:dispute_id

从回复中我们可以看到带有附件链接的文档: messages

文档下载地址: https://api-m.sandbox.paypal.com/v2/content/documents/DIS-010-8cd2522d-c20d-4917-a31d-b9683aa14f17/files/1/download

我在邮递员中尝试了带有标头和不记名令牌的获取请求

完整回复: {"name":"NOT_AUTHORIZED","debug_id":"9911d2bde7adc","message":"由于权限不足,授权失败。","details":[{"issue":"NOT_AUTHORIZED","description":"由于权限不足,授权失败。"}]}

我正在尝试使用此网址创建可下载链接 https://api-m.sandbox.paypal.com/v2/content/documents/DIS-010-8cd2522d-c20d-4917-a31d-b9683aa14f17/files/1/download

响应显示“NOT_AUTHORIZED”

我已检查贝宝争议文件。没有关于下载任何争议相关附件文件的明确说明。

php paypal-sandbox paypal-rest-sdk
1个回答
0
投票

我在获取

access token
API
时错过了发送 
v1/customer/disputes/:dispute_id

GET https://api-m.sandbox.paypal.com/v1/customer/disputes/:dispute_id

在 HTTP 请求中使用“Authorization: Bearer”令牌(例如使用 axios.get() 进行 GET 调用时)是一种发送访问令牌以进行身份验证和授权目的的方法

axios.get('https://api-m.sandbox.paypal.com/v1/customer/disputes/:dispute_id', {
  headers: {
    'Authorization': `Bearer ${accessToken}`
  }
})

我将演示三种方式 一个用于

curl
,另一个用于
node.js
axios

cURL
方式

CLIENT_ID=YOUR_CLIENT_ID \
CLIENT_SECRET=YOUR_CLIENT_SECRET \
echo "CLIENT_ID = "$CLIENT_ID \\
echo "CLIENT_SECRET = "$CLIENT_SECRET

ACCESS_TOKEN=$(curl --location 'https://api-m.sandbox.paypal.com/v1/oauth2/token' \
--silent \
--header 'Content-Type: application/x-www-form-urlencoded' \
--user "$CLIENT_ID":"$CLIENT_SECRET" \
--data-urlencode 'grant_type=client_credentials'| jq -r '.access_token') \
echo "ACCESS_TOKEN = "$ACCESS_TOKEN

curl --location 'https://api-
DISPUTE_ID=$(curl --location 'https://api-m.sandbox.paypal.com/v1/customer/disputes' \
--silent \
--header 'Authorization: Bearer '"$ACCESS_TOKEN" | jq -r '.items[0]'.dispute_id) \
echo "DISPUTE_ID = "$DISPUTE_ID

curl --location 'https://api-m.sandbox.paypal.com/v1/customer/disputes/'$DISPUTE_ID \
--silent \
--header 'Authorization: Bearer '"$ACCESS_TOKEN" | jq .

#1 cURL 结果

node.js

另存为

data.js

const axios = require('axios');
const CLIENT_ID = 'YOUR CLIENT_ID'
const CLIENT_SECRET = 'YOUR CLIENT_SECRET'
const getAccessToken = async () => {
    try {
        const response = await axios.post('https://api-m.sandbox.paypal.com/v1/oauth2/token', 'grant_type=client_credentials', {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            auth: {
                username: CLIENT_ID,
                password: CLIENT_SECRET
            }
        });

        const accessToken = response.data.access_token;
        return accessToken;

    } catch (error) {
        console.error("Error getting access token: ", error);
        throw error;  // Propagate the error
    }
};

const fetchDisputeData = async (accessToken, dispute_id) => {
    try {
      if (!accessToken) {
        throw new Error('Access token is not defined.');
      }
  
      const response = await axios.get(`https://api-m.sandbox.paypal.com/v1/customer/disputes/${dispute_id}`, {
        headers: {
          'Authorization': `Bearer ${accessToken}`
        }
      });
  
      console.log(response.data);
    } catch (error) {
      console.error('Error fetching dispute data:', error.message);
      throw error;  // Propagate the error
    }
};

(async () => {
    try {
        const accessToken = await getAccessToken();
        const DISPUTE_ID = 'PP-R-PNP-10089600';
        await fetchDisputeData(accessToken, DISPUTE_ID);
    } catch (error) {
        console.error('Error in async sequence:', error.message);
    }
})();

node.js 结果

邮递员方式

邮差结果

© www.soinside.com 2019 - 2024. All rights reserved.