MTN短信V3 API 401响应

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

帮助我解决我遇到的 mtn API 问题。 尽管我已经执行了正确的步骤,但我还是收到了 SMS v3 API 的 401 响应。 在此pastebin链接中找到我的测试脚本: https://pastebin.com/b1qyyvmY

API 链接如下: https://developers.mtn.com/products/sms-v3-api

#!/usr/bin/env python3

'''
This is a test script to send a message using the MTN API
AppName = bulkSMSSender
'''

import requests

# get access token for MTN API
import requests

url = "https://api.mtn.com/v1/oauth/access_token?grant_type=client_credentials"
payload = "client_id=OtYI2bLjnInCpyW1K6keohVZRKKIsz1f&client_secret=Hd3bmuAjAm44Ddmx"
headers = {
    'Content-Type': "application/x-www-form-urlencoded"
    }

token_response = requests.request("POST", url, data=payload, headers=headers)

# get access token using get() method
token = token_response.json().get('access_token')

print(token_response.text)

print('token: ', token)
print('---------------------------------')

# send message using the access token
url = "https://api.mtn.com/v3/sms/messages/sms/outbound"

payload = {
    "senderAddress": "VALCO",
    "receiverAddress": ["233548257283", "233202419977"],
    "message": "Test message from VALCO",
    "clientCorrelatorId": "test123",
    "keyword": "string",
    "serviceCode": "1000",
    "requestDeliveryReceipt": False
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer " + token
}
print(headers)

try:
    response = requests.request("POST", url, json=payload, headers=headers)
    print(response.status_code)
    message = response.json()
    print(response.text)
except:
    print("Message not sent")

收到此回复

koby@PC1172:~/specialization_portifolio_projec/mtn_api$ python3 py_test_send_api.py 
{
  "refresh_token_expires_in" : "0",
  "api_product_list" : "[SMS v3 API]",
  "api_product_list_json" : [ "SMS v3 API" ],
  "organization_name" : "mtn-prod",
  "developer.email" : "[email protected]",
  "token_type" : "BearerToken",
  "issued_at" : "1685467850709",
  "client_id" : "OtYI2bLjnInCpyW1K6keohVZRKKIsz1f",
  "access_token" : "gwkF3TjUf6QKOX654xQTaGA4yzDA",
  "application_name" : "f8d79225-e011-4983-bc0e-c85937386be3",
  "scope" : "",
  "expires_in" : "3599",
  "refresh_count" : "0",
  "status" : "approved"
}
token:  gwkF3TjUf6QKOX654xQTaGA4yzDA
---------------------------------
{'Content-Type': 'application/json', 'Authorization': 'Bearer gwkF3TjUf6QKOX654xQTaGA4yzDA'}
401

                {
                  "statusCode": 4000,
                  "statusMessage": "Unauthorised.",
                  "supportMessage": "Please verify token environment and key.",
                  "faultMessage1" : "keymanagement.service.InvalidAPICallAsNoApiProductMatchFound",
                  "faultMessage2" : ""
                }

上面已经解释了一切。

python sms
1个回答
0
投票

MTN 短信 v3 在加纳不起作用 尝试 v2

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