我正在尝试使用 Gmail API 发送电子邮件。但我收到这个错误
googleapi:错误 403:请求的身份验证范围不足。更多详细信息:原因:权限不足,消息:权限不足
我认为这可能与配置有关,我还遵循了 google 的 Go 快速入门,这里是 getClient 函数:
func getClient(config *oauth2.Config) *http.Client {
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
tokFile := "token.json"
tok, err := tokenFromFile(tokFile)
if err != nil {
tok = getTokenFromWeb(config)
saveToken(tokFile, tok)
}
return config.Client(context.Background(), tok)
}
Run Code Online (Sandbox Code Playgroud)
这是发送的代码:
case "pass":
templateData := struct {
VerPass string
}{
VerPass: cont1,
}
emailBody, …Run Code Online (Sandbox Code Playgroud) 我开始使用 Golang 来使用 Google Play 开发者报告 API(https://pkg.go.dev/google.golang.org/api@v0.79.0/playdeveloperreporting/v1beta1),并面临与 API 范围相关的问题:
代码:
package main
import (
"context"
"encoding/json"
"fmt"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"golang.org/x/oauth2/jwt"
"google.golang.org/api/option"
"google.golang.org/api/playdeveloperreporting/v1beta1"
"io/ioutil"
)
const (
GoogleApplicationCredentials = "path_to_service_account_credentials"
ProjectID = "apps/{project_id}"
)
func main() {
tokenSource, err := getTokenSource(GoogleApplicationCredentials)
if err !=nil {
panic(err)
}
if err := getAnomalies(tokenSource, ProjectID); err != nil {
panic(err)
}
}
func getAnomalies(tokenSource oauth2.TokenSource, projectID string) error {
ctx := context.Background()
service, err := playdeveloperreporting.NewService(ctx, option.WithTokenSource(tokenSource))
if err != nil { …Run Code Online (Sandbox Code Playgroud) google-api go google-play-developer-api google-api-go-client
我正在使用 Google 新 People API 制作应用程序原型。在测试过程中,我批量添加和删除了联系人,看看每分钟和每天总共可以添加多少个联系人。
我理解文档说每分钟可以添加多少个,但从我的测试来看,我似乎没有接近这个。即使在查看我的指标时,我的请求也远远超出了每分钟和每天的假定限制。
我的主要问题是,在我的 3 个 Gmail 帐户上的服务帐户上进行了几次尝试后,我现在回来了googleapi: Error 429: MY_CONTACTS_OVERFLOW_COUNT, rateLimitExceeded。我在网上找不到任何提及MY_CONTACTS_OVERFLOW_COUNT。我从错误中假设这意味着我有太多联系人,但是当运行删除脚本时,似乎我根本没有任何联系人。现在我的开发计算机上的所有 3 个帐户都返回此响应超过 24 小时,这让我相信我可能已被阻止并且不受速率限制?
用于运行测试的客户端代码:
package main
import (
"context"
"log"
"google.golang.org/api/people/v1"
"os"
"bufio"
"time"
//"github.com/davecgh/go-spew/spew"
)
func chunks(xs []string, chunkSize int) [][]string {
if len(xs) == 0 {
return nil
}
divided := make([][]string, (len(xs)+chunkSize-1)/chunkSize)
prev := 0
i := 0
till := len(xs) - chunkSize
for prev < till {
next := prev + chunkSize
divided[i] = xs[prev:next] …Run Code Online (Sandbox Code Playgroud) 我正在按照go faststart gmail api中的步骤操作。
在函数上getTokenFromWeb,粘贴长网址
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=abcdefg.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.readonly&state=state-token
或者
http://localhost:8000
结果是
无法访问该网站。本地主机拒绝连接。ERR_CONNECTION_REFUSED
遵循相同的快速入门,但对于 python 来说可以完美地工作。
如果我通过 python 获取令牌并在 Go 快速入门中使用它,它也可以工作。所以问题就出在网络检索的令牌上。
我想列出带有特定标签的消息。所以我使用了谷歌的Go Quickstart 代码并将范围设置为 gmail.MailGoogleComScope。
使用此代码获取带有标签“INBOX”的所有邮件列表可以正常工作
mes, err := srv.Users.Messages.List(user).LabelIds("INBOX").Do()
Run Code Online (Sandbox Code Playgroud)
但是当我用“测试”替换“收件箱”时,出现错误:
无法检索消息。googleapi:错误 400:无效标签:TEST,invalidArgument 退出状态 1
并且有一个名为 TEST 的标签。我究竟做错了什么?