可以使用 Python 的 requests 库来读取 Salesforce REST API 的数据。首先,你需要在 Salesforce 中设置一个连接器,并获取连接器的访问令牌。然后,你可以使用 requests 库发送 HTTP 请求来访问 Salesforce REST API。
例如,你可以使用以下代码来检索 Salesforce 中的联系人数据:
import requests# Set the request headers
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
}
# Set the API endpoint
url = 'https://YOUR_INSTANCE.salesforce.com/services/data/v50.0/sobjects/Contact'
# Make the GET request
response = requests.get(url, headers=headers)
# Print the response
print(response.json())
其中,YOUR_ACCESS_TOKEN
是你获取的访问令牌,YOUR_INSTANCE
是你的 Salesforce 实例的名称。
请注意,你可能还需要处理错误响应、分页等其他情况。有关使用 Python 访问 Salesforce REST API 的更多信息,可以参考 Salesforce 的 REST API 开发指南。