哪些Google Domain Verification API用于发布/订阅域验证?

时间:2018-12-12 00:48:58

标签: node.js typescript google-api google-cloud-platform

我有此代码,该代码获取域令牌并使用Site Verification API与Google验证域:

const auth = await this.gcp.getApplicationCredential(accountId, projectId,[
    'https://www.googleapis.com/auth/siteverification',
    'https://www.googleapis.com/auth/siteverification.verify_only'     
]);
const siteVerification = this.google.siteVerification({
    version: 'v1',
    auth
});      
const res = await siteVerification.webResource.getToken({
    requestBody: {
        verificationMethod: "FILE",
        site: {
            identifier: siteUrl,
            type: "SITE"
        }
    }
});
await siteVerification.webResource.insert({
   verificationMethod: "FILE",
   requestBody: {
       site: {
           identifier: siteUrl,
           type: "SITE",
        },
   }
});

执行完此操作后,我可以在UI中看到该网站已通过验证: enter image description here

然后,我使用Search Console API将网站添加到Search Console:

const auth = await this.gcp.getApplicationCredential(accountId, projectId,[
    'https://www.googleapis.com/auth/webmasters'  
]);
const webVerification = this.google.webmasters({
    version: 'v3',
     auth
});
await webVerification.sites.add({
    siteUrl
});

当我像这样对API执行GET时:

const site = await webVerification.sites.get({
    siteUrl
});

我可以看到我的API调用成功:

{
   “siteUrl”: “https://fakewebsite.com/“,
   “permissionLevel”: “siteOwner”
}

这就是问题所在: 当我查看项目中的UI时,看不到验证信息: enter image description here 当我尝试使用推送端点创建预订时,我的API调用失败:

await pubsub.projects.subscriptions.create({
    name: subscription,
    requestBody: {
        topic: topicName,
        pushConfig: {
            pushEndpoint
        },
    }
});

出现此错误:

{"errorType":"Error","errorMessage":"The supplied HTTP URL is not registered in the subscription's parent project (url=\"https://fakewebsite.com/c050d966-b62c-4cc8-9cc9-d431e8d8f14c/suggestions\", project_id=\"9999999999\").

有人知道我在做什么错吗?

1 个答案:

答案 0 :(得分:1)

我今天从Google Iam工程团队那里得到了这个问题的答案。 Google Cloud当前没有用于域验证的API。必须通过UI来完成。他们确实向我提出了功能请求,因此如果有可用信息,我会进行更新。