我正在致力于让贝宝卖家加入我的平台。 我正在关注这个 paypal 推荐
但是我收到了这个错误
{ "msg": "{"name":"NOT_AUTHORIZED","debug_id":"f88411690d4c9","message":"由于权限不足,授权失败。","details":[{"issue":"NOT_AUTHORIZED", "description":"由于权限不足,授权失败。"}]}" }
有人可以详细说明需要哪些权限以及我如何获得这些权限
我正在使用此代码
@staticmethod
def create_paypal_referral(email, tracking_id, return_url):
"""Create a PayPal partner referral."""
success = False
response = None
try:
# Get access token
access_token = PaypalrestSDk.get_access_token()
print(access_token)
# Define headers and payload for the referral request
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {access_token}',
}
data = json.dumps({
"email": email,
"tracking_id": tracking_id,
"partner_config_override": {
"return_url": return_url,
"return_url_description": "The URL to return the merchant after the PayPal onboarding process.",
"show_add_credit_card": True
},
"operations": [
{
"operation": "API_INTEGRATION",
"api_integration_preference": {
"rest_api_integration": {
"integration_method": "PAYPAL",
"integration_type": "THIRD_PARTY",
"third_party_details": {
"features": ["PAYMENT", "REFUND", "PARTNER_FEE"]
}
}
}
}
],
"products": ["PAYMENT_METHODS"],
"capabilities": ["APPLE_PAY"],
"legal_consents": [
{
"type": "SHARE_DATA_CONSENT",
"granted": True
}
]
})
# Make the request to PayPal's partner referrals API
referral_url = f'{settings.PAYPAL_BASE_URL}/v2/customer/partner-referrals'
response = requests.post(referral_url, headers=headers, data=data)
if response.status_code == 201:
success = True
response = response.json()
else:
response = response.text
return success, response
except Exception as e:
response = str(e)
return success, response
@staticmethod
def get_access_token():
"""Retrieve an access token using PayPal OAuth2 API."""
oauth_url = f'{settings.PAYPAL_BASE_URL}/v1/oauth2/token'
response = requests.post(
oauth_url,
headers={'Accept': 'application/json', 'Accept-Language': 'en_US'},
auth=HTTPBasicAuth(settings.PAYPAL_CLIENT_ID, settings.PAYPAL_CLIENT_SECRET),
data={'grant_type': 'client_credentials'}
)
if response.status_code == 200:
return response.json().get('access_token')