php - 获取 401 Unauthorized Xero oAuth 2.0 -
问题描述
我正在尝试使用 Xero oAuth 2.0 创建一个新联系人并收到此错误:
[401] Client error: `PUT https://api.xero.com/api.xro/2.0/Contacts?summarizeErrors=true` resulted in a `401 Unauthorized` response:
我的范围为:
'scopes' => [
'openid',
'email',
'profile',
'offline_access',
'accounting.settings',
'accounting.contacts',
'accounting.reports.read',
],
我能够连接到 Xero(使用此代码)并收到消息The App is connected to Xero但是当我使用以下代码时:-
public function xeroTest(OauthCredentialManager $xeroCredentials) {
$apiInstance = resolve(\XeroAPI\XeroPHP\Api\AccountingApi::class);
$contact = resolve( \XeroAPI\XeroPHP\Models\Accounting\Contact::class);
$contact->setName('Abcdef');
$contact->setContactId('6d42f03b-181f-43e3-93fb-2025c0hjhe92');
$apiResponse = $apiInstance->createContacts($xeroCredentials->getTenantId() ,$contact,true);
$message = 'New Contact Name: ' . $apiResponse->getContacts()[0]->getName();
return $message;
}
错误:[401] 客户端错误:PUT https://api.xero.com/api.xro/2.0/Contacts?summarizeErrors=true
导致401 Unauthorized
响应:
解决方案
我没有看到您的所有代码,但您可能只需要在 PHP 客户端上设置有效的access_token 。
推荐阅读
- c# - GetAllocatedBytesForCurrentThread() 如何工作?如何获得线程使用的内存?
- java - 如何从内部存储中提取 zip 文件?
- javascript - 从动态表创建中计算行数的问题
- r - 如何结合 facet_grid 和 ggstatsplot::grouped_ggbetweenstats?
- jquery - 为什么这只发生在ipad上?jQuery显示下拉菜单发生了两次
- python - 重新训练后的Tensorflow label_image NotFoundError
- c# - [] 内的索引数量错误;预计 2
- bash - bash 逐行更改文件中的绝对路径以创建脚本
- python-2.7 - 无法通过 python paramiko 连接到远程服务器
- java - 检测文件是否已被另一个程序打开并检测该程序