- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用服务帐户通过 Google 我的商家 API 检索位置/评论。
到目前为止我有:
当使用 Google 的示例 .NET 客户端以编程方式列出来自 https://mybusiness.googleapis.com/v4/accounts/[ACCOUNT NAME]/invitations
的邀请时,我能够看到邀请从https://developers.google.com/my-business/samples下载
但是,当我尝试通过 https://mybusiness.googleapis.com/v4/accounts/[ACCOUNT NAME]/invitations/[INVITATION NAME]:accept
接受邀请时,请求失败出现 500 服务器错误。
在创建 MyBusinessService
实例时,我首先创建一个服务帐户凭据,如:
ServiceAccountCredential credential;
using (Stream stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read, FileShare.Read))
{
credential = (ServiceAccountCredential)GoogleCredential
.FromStream(stream)
.CreateScoped(new [] { "https://www.googleapis.com/auth/plus.business.manage" })
.UnderlyingCredential;
}
接下来我创建一个初始化程序,例如:
var initializer = new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "My GMB API Client",
GZipEnabled = true,
};
最后,我创建了一个 MyBusinessService
实例,如下所示:var service = new MyBusinessService(initializer);
我可以列出邀请:
service.Accounts
.Invitations
.List("[ACCOUNT NAME]")
.Execute()
.Invitations;
但是,尝试接受邀请失败:
service.Accounts
.Invitations
.Accept(null, "[INVITATION NAME]")
.Execute();
第一个参数是null
as this documentation声明请求正文应为空。
或者是否有其他方式接受邀请以使服务帐户能够检索“Google 我的商家”对我们营业地点的评论?
最佳答案
要作为服务器到服务器身份验证的服务帐户登录,您需要为您的服务帐户启用域范围的委派。 https://developers.google.com/admin-sdk/directory/v1/guides/delegation
执行此操作后,您可以通过冒充已获批准的“我的商家”经理的电子邮件地址,让您的服务帐户登录“Google 我的商家”API。这是在 NodeJS 中,这是我使用的:
const { google } = require('googleapis'); // MAKE SURE TO USE GOOGLE API
const { default: axios } = require('axios'); //using this for api calls
const key = require('./serviceaccount.json'); // reference to your service account
const scopes = 'https://www.googleapis.com/auth/business.manage'; // can be an array of scopes
const jwt = new google.auth.JWT({
email: key.client_email,
key: key.private_key,
scopes: scopes,
subject: `impersonated@email.com`
});
async function getAxios() {
const response = await jwt.authorize() // authorize key
let token = response.access_token // dereference token
console.log(response)
await axios.get('https://mybusiness.googleapis.com/v4/accounts', {
headers: {
Authorization: `Bearer ${token}`
} // make request
})
.then((res) => { // handle response
console.log(res.data);
})
.catch((err) => { // handle error
console.log(err.response.data);
})
}
await getAxios(); // call the function
关于google-api - 以编程方式接受服务帐户的“Google 我的商家”邀请,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58376478/
我需要 paypal 集成来支付订单。我已经做的是集成 api http://ci-merchant.org/ .它的工作原理就像它需要.. 去 Paypal 网站,让我选择支付,但在我按下支付按钮后
我有一个项目有许多不同的构建配置,4 个用于一个开发人员帐户,3 个用于另一个,每个都有生产、alpha 和 beta 构建配置,第一个有调试配置。所有 7 个都有不同的包 ID 每个开发者帐户都使用
我是一名优秀的程序员,十分优秀!