php - XERO PHP SDK - Createinvoiceattachment 抛出 401 Unauthorized 错误
问题描述
我正在尝试将文档附加到发票上。它抛出错误。租户 ID、发票 ID 正确。
调用 AccountingApi->createInvoiceAttachmentByFileName 时出现异常:[401] 客户端错误:
PUT https://api.xero.com/api.xro/2.0/Invoices/b03b18ca-50b2-42fa-a585-aa5674b7ed03/Attachments/2New-Requirment-Oct2020.docx?IncludeOnline=true
导致401 Unauthorized
响应:{"Type":null,"Title":"Unauthorized","Status":401,"Detail":"AuthorizationUnsuccessful","Instance ":"54c33c01-e168-47d5-abe (截断...)
我的代码是:
if (isset($_FILES["gfile1"]))
{
$target_dir = "uploads/bills/";
$target_file = $target_dir . basename($_FILES["gfile1"]["name"]);
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);
$filename1 = $billid . basename($_FILES["gfile1"]["name"]);
$filename1 = str_replace(" ", "", $filename1);
$filename1 = str_replace("#", "", $filename1);
$target_filenew = $target_dir . $filename1;
move_uploaded_file($_FILES["gfile1"]["tmp_name"], $target_filenew);
$attachmentFile = file_get_contents(base_url() . $target_filenew);
try {
$result = $accountingApi->createInvoiceAttachmentByFileName($xeroTenantId, $invid, $filename1,
$attachmentFile, true);
} catch (Exception $e) {
echo 'Exception when calling AccountingApi->createInvoiceAttachmentByFileName: ',
$e->getMessage(), PHP_EOL;
}
}
解决方案
附件需要使用不同的范围。
您在授权连接时是否在请求的范围中包含了“accounting.attachments”范围?
推荐阅读
- gradle - Gradle:重试失败的依赖项下载
- pandas - 如何将 1 分钟数据转换为 5 分钟 OHLC 数据(用于交易)
- firebase - Expo:由于 Firebase 项目 ID 无效(Android),无法获取 getDevicePushTokenAsync
- elixir - 计算 current_visitors 和 current_users
- python - 根据csv中的文件夹名称列表从文件夹中提取文件
- python - 运行for循环时出现投资错误:ConnectionError:ERR#0015:错误406,稍后再试
- firebase-realtime-database - 使用 Firebase reyclerview 适配器实现 searchview
- c# - 如何将文本框列表与并行列表进行比较?
- python - 带有 Python API 的 Django?
- android - 在另一个 RecyclerView 内滚动 RecyclerView 自动无法正常工作