gpt4 book ai didi

javascript - 用于 ai SEO 网站审核的 Google Sheet Script 的权限问题

转载 作者:行者123 更新时间:2023-12-02 05:46:24 24 4
gpt4 key购买 nike

我正在尝试实现一篇文章中的代码片段,以帮助完成一些家庭/爱好 SEO 项目。该脚本应拉取网站、运行审核并提出建议。我遇到了 Google 阻止请求的权限问题。一切都在我的个人帐户中完成,所以我不确定在哪里需要修改哪些权限(或如何)。代码片段如下:

/**
* Performs a content audit on the specified URL, using OpenAI's language model to provide a quality rating and actionable recommendations.
*
* @param {string} url The URL to audit.
* @return The content quality rating and recommendations as provided by the language model.
* @customfunction
*/
function performContentAudit(url) {
// Get the active sheet and the range of values to audit
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getDataRange();
var values = range.getValues();

// Loop through each URL in the range and perform an audit
for (var i = 0; i < values.length; i++) {
if (values[i][0] === url) { // check if this is the URL we want to audit
var prompt = "I would like you to audit content ...: " + url;

// Call the OpenAI API to perform the audit
var response = UrlFetchApp.fetch("https://api.openai.com/v1/engines/davinci-codex/completions", {
'method': 'post',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer openai API KEY '
},
'payload': JSON.stringify({
'prompt': prompt,
'temperature': 0.5,
'max_tokens': 1024
})
});

// Parse the API response and get the audit results
var json = JSON.parse(response.getContentText());
var answer = json.choices[0].text;

// Return the audit results
return answer;
}
}

// Return an error message if the specified URL was not found
return "Error: URL not found in sheet";
}

系统提示我允许权限,但随后收到错误消息:

This app is blockedThis app tried to access sensitive info in your Google Account. To keep your account safe, Google blocked this access.

欢迎任何想法。

最佳答案

根据类似案例,在您的 Google Cloud 控制台中创建一个新项目并将项目 ID 分配给 Apps Script 项目可以让您顺利授权。

步骤如下:

  1. 转到 https://console.cloud.google.com/

  2. Create a new project

  3. 转到侧边栏菜单上的“OAuth 同意屏幕”。

    • 配置项目设置,对于免费的 Gmail 帐户,选择“外部”用户类型。
    • 设置应用名称用户支持邮箱开发者联系信息
    • 保存并继续。
  4. 转到边栏菜单并转到APIs & Services > Library,搜索 Drive API、Sheets API 并启用这两项服务。

  5. 点击右上角的三个点,选择“Project settings”,复制Project number

  6. 返回您的 Apps 脚本项目,转到边栏菜单并转到 Project Settings

  7. 转到 Google Cloud Platform (GCP) Project 部分并插入第 (5) 步中的项目编号。

  8. 最后再次运行脚本,系统会要求您授权,这次它应该可以让您继续而不会出现问题。

可以看到更详细的步骤here .

关于javascript - 用于 ai SEO 网站审核的 Google Sheet Script 的权限问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75687828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com