我有一个桌面应用程序,通过REST接口使用GMAIL API读取邮件.我想使用服务帐户,以便我们可以使用域设置下载邮件,用户交互为空.我已成功创建Gmail服务实例,但当我尝试访问任何Gmail API方法(如提取邮件列表或其他任何内容)时,我会收到例外说法
Google.Apis.Auth.OAuth2.Responses.TokenResponseException:错误:"access_denied",说明:"请求的客户端未经授权."
我完成了开发人员控制台的所有设置,并将范围添加到我的gapps域.
Gmail API是否支持服务帐户?使用相同的设置和服务帐户,我可以使用云服务和API获取Google云端硬盘中所有文件的列表.
我正在使用GMail API来检索电子邮件内容.我正在为身体获得以下base64编码数据:http://hastebin.com/ovucoranam.md
但是,当我通过base64解码器运行它时,它返回一个空字符串(错误)或类似于HTML数据的东西,但有一堆奇怪的字符.
救命?
标题说明了一切,但我想知道Gmail线程ID是否在用户中是唯一的.由于各种原因,我想根据这些ID索引全局数据结构.
我正在尝试使用Android应用程序访问Gmail API.我已成功请求并使用所有可用范围组合接收了访问令牌.但似乎每次我实际尝试使用Gmail API命令时,我都会得到一个403 exception reading: Access not configured please use Google developers console to activate the api...
不用说,API已激活,并且使用正确的包名称和sha1代码创建了客户端密钥.相同的客户端ID适用于Google Plus功能.
是否有任何人遇到此问题或成功连接到Android的Gmail API?
谢谢
这是日志:
09-04 21:40:54.014: W/System.err(26717): com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
09-04 21:40:54.014: W/System.err(26717): {
09-04 21:40:54.014: W/System.err(26717): "code" : 403,
09-04 21:40:54.014: W/System.err(26717): "errors" : [ {
09-04 21:40:54.014: W/System.err(26717): "domain" : "usageLimits",
09-04 21:40:54.014: W/System.err(26717): "message" : "Access Not Configured. Please use Google Developers Console to activate the API for your project.",
09-04 21:40:54.014: W/System.err(26717): "reason" : "accessNotConfigured"
09-04 …
Run Code Online (Sandbox Code Playgroud) android google-oauth google-schemas google-oauth-java-client gmail-api
我正在尝试使用google java api服务发送基于Gmail REST API的邮件.我已通过Google Develover Console配置了应用程序客户端并下载了p12和json文件.
我使用过这个示例程序,https://developers.google.com/gmail/api/guides/sending#sending_messages ...
此示例有效,但这是基于GoogleAuthorizationCodeFlow.我只想从服务器到服务器工作,直接调用,而不是打开浏览器来获取访问令牌......我得到了它(访问令牌)但最后我收到了错误请求....为什么? ?我收到的信息不仅仅是"Bad Request"和"Precondition Failed"
基于此,我按照以下步骤操作:
第一步:根据我的客户帐户邮件和p12生成的文件创建GoogleCredential对象:
GoogleCredential credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport())
.setJsonFactory(new JacksonFactory())
.setServiceAccountId(serviceAccountUserEmail)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(
new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
.build();
Run Code Online (Sandbox Code Playgroud)在这里,我必须指出,我有很多问题需要使用ClientID而不是ClientMail.它必须使用@ developer.gserviceaccount.com帐户而不是.apps.googleusercontent.com.如果你不发送这个参数确定,你得到一个"无效授予"错误.这在此处说明:https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtAuthorization
第二步:根据凭据创建Gmail服务:
Gmail gmailService = new Gmail.Builder(httpTransport,
jsonFactory,
credential)
.setApplicationName(APP_NAME)
.build();
Run Code Online (Sandbox Code Playgroud)第三步从MimmeMessage创建Google原始消息:
private static Message _createMessageWithEmail(final MimeMessage email) throws MessagingException, IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
email.writeTo(bytes);
String encodedEmail = Base64.encodeBase64URLSafeString(bytes.toByteArray());
Message message = new Message();
message.setRaw(encodedEmail);
return message;
Run Code Online (Sandbox Code Playgroud)
}
第四步调 …
我在本文档后面获得了授权码.但是当我试图获得访问令牌时,我总是遇到错误.谁能帮我 ?
public String AccessToken()
{
String accessToken = "";
StringBuilder strBuild = new StringBuilder();
String authURL = "https://accounts.google.com/o/oauth2/token?";
String code = "4/SVisuz_x*********************";
String client_id = "******************e.apps.googleusercontent.com";
String client_secret = "*******************";
String redirect_uri = "urn:ietf:wg:oauth:2.0:oob";
String grant_type="authorization_code";
strBuild.append("code=").append(code)
.append("&client_id=").append(client_id)
.append("&client_secret=").append(client_secret)
.append("&redirect_uri=").append(redirect_uri)
.append("&grant_type=").append(grant_type);
System.out.println(strBuild.toString());
try{
URL obj = new URL(authURL);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Host", "www.googleapis.com");
//BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(con.getOutputStream()));
//bw.write(strBuild.toString());
//bw.close();
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(strBuild.toString());
wr.flush();
wr.close();
//OutputStreamWriter out …
Run Code Online (Sandbox Code Playgroud) 我正在从Node.JS中的Google Gmail API中检索邮件,但我无法生成或检索到电子邮件的直接链接.
目前,我使用以下代码:
var link = 'https://mail.google.com/mail/u/0/#inbox/' + messageContent.threadId;
但正如你所看到的,它总是导航到用户的主要收件箱(/u/0/
).我尝试链接的电子邮件位于我的第二个和第三个收件箱中.
我尝试使用get message调用获取电子邮件的收件箱号码,但不幸的是它没有返回该数据.
我也尝试了下面这段代码,但它也没有用.它只是加载我的主要收件箱.
var link = 'https://mail.google.com/mail/#inbox/' + messageContent.threadId;
有人知道如何生成电子邮件的正确和直接链接吗?
提前致谢.
测试用例
首先,登录Google中的两个或多个帐户.如下图所示,我登录了3个帐户.第一个(在顶部)是我的主要帐户.其他的是二级账户.
与我的主Gmail的直接链接是:https://mail.google.com/mail / u/0 / #inmpbox /
与我的第二个帐户的直接链接是:https: //mail.google.com/mail / u/1 / #inmpbox /
我的第三个帐户和最后一个帐户的链接是:https: //mail.google.com/mail / u/2 / #inmpbox/
这些数字取决于您登录帐户的顺序.您登录的第一个帐户将始终是您的主帐户.
所以我们以2527bfcqed7d54c1
消息ID为例.唯一剩下的就是生成与消息的直接链接,但问题是,我们只知道它链接到的电子邮件,而不是收件箱的数量(例如/u/2
).
因此,如果邮件存在于收件箱中,/u/2
我们无法获得直接链接.由于API未返回收件箱编号,https://mail.google.com/mail/#inbox/2527bfcqed7d54c1
因此始终会重定向到主收件箱/u/0
.
我在使用Gmail API向多个地址发送邮件时遇到问题.我已经成功地只向一个地址发送了一条消息,但是当我在'To'
字段中包含多个以逗号分隔的地址时,会收到以下错误:
发生错误:https: //www.googleapis.com/gmail/v1/users/me/messages/send ?alt = json 返回"标题无效">
我正在使用此Gmail API指南中的CreateMessage
和SendMessage
方法:https:
//developers.google.com/gmail/api/guides/sending
该指南指出Gmail API需要符合RFC-2822的邮件.我再次使用RFC-2822指南中的一些寻址示例没有太多运气:https: //tools.ietf.org/html/rfc2822#appendix-A
我的印象是'mary @ x.test,jdoe @ example.org,one @ y.test'应该是一个有效的字符串,以传递给'to'参数CreateMessage
,但是我收到的错误SendMessage
引导我否则相信.
如果您可以重新创建此问题,或者您对我可能犯错误的地方有任何建议,请告诉我.谢谢!
编辑:这是产生错误的实际代码......
def CreateMessage(sender, to, subject, message_text):
message = MIMEText(message_text)
message['to'] = to
message['from'] = sender
message['subject'] = subject
return {'raw': base64.urlsafe_b64encode(message.as_string())}
def SendMessage(service, user_id, message):
try:
message = (service.users().messages().send(userId=user_id, body=message)
.execute())
print 'Message Id: %s' % message['id']
return message
except errors.HttpError, error: …
Run Code Online (Sandbox Code Playgroud) 我正在使用Google推送通知与Google PubSub,并有一个自定义标签,我想监视任何更改.我使用以下代码为标签注册手表(标签的标识为Label_1)
WatchRequest wr = new WatchRequest();
wr.TopicName = "projects/" + primaryLink.ggProjectId + "/topics/iLink" + segmentId;
if (labels != null && labels.Count > 0)
{
wr.LabelIds = new List<string>();
wr.LabelIds.Add("Label_1");
wr.LabelFilterAction = "include";
}
WatchResponse wrr = gs.Users.Watch(wr, emailAccount).Execute();
return "HistoryId " + wrr.HistoryId.ToString();
Run Code Online (Sandbox Code Playgroud)
}
手表注册正常.问题是我收到任何Gmail更改的推送通知,而不仅仅是标签下的更改.
是否支持自定义标签?
我在 Google App Engine 上运行的 django 网站上出现 500 服务器错误。当我查看 Google App Engine 日志时,我看到以下错误:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest returned "The caller does not have permission">
当我硬刷新浏览器时,这个错误就会消失。然后过了一段时间它又弹回来了。发生在移动设备(firefox、safari)、笔记本电脑(firefox、chrome)上。
更新:
在 Django settings.py 中,我有以下代码。它的最后一行生成错误:
pickle_path = 'token.pickle' # path to token.pickle
with open(pickle_path, 'rb') as token:
creds = pickle.load(token)
SERVICE = build('gmail', 'v1', credentials=creds) # ERROR LINE
Run Code Online (Sandbox Code Playgroud)
当我在本地运行 django 服务器时:出现以下错误:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest returned "The caller does not have permission">
Run Code Online (Sandbox Code Playgroud)
当我从终端重新启动 cloud sql 连接时 - 错误消失了。直到几天前,这种情况从未发生过。