新的Gmail API现在允许对标签中的总电子邮件和未读电子邮件进行邮件计数.但我无法让它工作并尝试了很多东西.它正确连接到Oauth,但无法使计数生效.我正在使用以下代码: -
$labelall = $service->users_labels->listUsersLabels('me');
$labels = $labelall->getLabels();
foreach ($labels as $label) {
print 'Label with ID: ' . $label->getId() . ',
Number of Messages:'.$label->getMessagesTotal().'<br/>';}
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?它正确列出标签,但消息计数返回null.
谢谢!
我正在尝试使用Gmail REST API读取/写入Gmail邮箱中的电子邮件/文件夹.添加以下Google身份验证范围时,可以从Gmail REST API中读取电子邮件,而不会出现任何问题:
https://apps-apis.google.com/a/feeds/compliance/audit/, https://www.googleapis.com/auth/admin.directory.user.readonly,https://www.googleapis.com /auth/gmail.readonly, https://www.googleapis.com/auth/admin.directory.group.member.readonly,https://www.googleapis.com/auth/admin.directory.group.readonly
注意:参数https://www.googleapis.com/auth/gmail.readonly正确允许用户从邮箱中读取.
但是,我也需要能够删除电子邮件.因此,根据https://developers.google.com/gmail/api/auth/scopes?hl=ja上的文档,只需要包含https://mail.google.com/代替https: //www.googleapis.com/auth/gmail.readonly.添加以下auth范围时:
https://apps-apis.google.com/a/feeds/compliance/audit/, https://www.googleapis.com/auth/admin.directory.user.readonly,https://mail.google.com /, https://www.googleapis.com/auth/admin.directory.group.member.readonly,https://www.googleapis.com/auth/admin.directory.group.readonly
...输出的错误如下:
2015-07-27 10:27:59 i.c.s.a.cv [DEBUG] failed get labels for user
com.google.api.client.auth.oauth2.TokenResponseException: 403 Forbidden
{
"error" : "access_denied",
"error_description" : "Requested client not authorized."
}
Run Code Online (Sandbox Code Playgroud)
当然,谷歌这是不正确的?我错过了什么?文档不正确吗?需要添加什么认证范围?
我正在与Java Google API客户端库连接.请参阅:https://developers.google.com/api-client-library/java/google-api-java-client/reference/1.20.0/overview-summary
删除请求如下:
public void deleteMessages(Queue<String> messages, GoogleUserAdapter user) throws Exception {
Gmail gmail = …Run Code Online (Sandbox Code Playgroud) 我试图用自定义标头搜索gmail api(这种情况下它被命名为 notification-id),但它不起作用.请求我正在制作:
GET https://www.googleapis.com/gmail/v1/users/tme/messages?includeSpamTrash=true&q=notification-id%3A560d01cef318893c3c000016
Run Code Online (Sandbox Code Playgroud)
我使用来自google mail api的默认标头(rfc822msgid)尝试了相同的查询,它可以处理此请求:
GET https://www.googleapis.com/gmail/v1/users/me/messages?includeSpamTrash=true&q=rfc822msgid%3A560d01d068c_6690c6f31857290%40ip-172-31-12-127.mail
任何想法为什么它不适用于自定义标题?
在他们的文档中,链接似乎都解析为https://developers.google.com/apps-marketplace/ - 似乎没有任何号召性用语.如何测试Gmail上下文小工具?在哪里上传清单和小工具规范?
我正致力于使用JavaScript Gmail API创建标签.
function createLabel(userId, newLabelName, callback) {
var request = gapi.client.gmail.users.labels.create({
'userId': userId,
'label': {'name': newLabelName}
});
request.execute(callback);}
Run Code Online (Sandbox Code Playgroud)
我能够进行身份验证,甚至我将获得标签列表,但在创建标签时,我收到以下错误.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Invalid request"
}
],
"code": 400,
"message": "Invalid request"
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用Try It示例时它正在工作,但唯一不同的是它使用key = {Your auth key}执行POST请求,该示例提供的不会将该部分附加到URL.
我正在开发一个使用GMail API发送电子邮件的Android应用程序.我在Android Quickstart和发送电子邮件时使用了示例代码,当我调试应用程序时,一切正常.当我用它构建发布版本时会出现问题minifyEnabled=true.在这种情况下,调用service.users().messages().send(userId, message).execute();会出错IOException.异常消息是"404 Not Found".
ProGuard的文件包括所有的-keep class和-dontwarn我在其他帖子发现:
-dontwarn com.google.**
-dontwarn java.awt.**
-dontwarn javax.security.**
-dontwarn java.beans.**
-keep class com.google.**
-keep public class Mail {*;}
-keep class com.sun.activation.** {*;}
-keep class com.sun.activation.registries {*;}
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class …Run Code Online (Sandbox Code Playgroud) 我正在使用javascript gmail api来使用threadId获取电子邮件线程.我使用以下代码:
var request = gapi.client.gmail.users.threads.get({
'userId': 'me',
'id': '123abc'
});
request.execute(function(response) {
var messages = response.messages;
});
Run Code Online (Sandbox Code Playgroud)
这是第一次特定的threadId,它工作正常.并且对于进一步的请求,即使线程有更多的电子邮件,它也会返回相同数量的消息.但是,如果我从Chrome开发者工具 - 网络选项中清除gapi网址的浏览器缓存,则响应会提供正确数量的电子邮件.
例:
- >使用threadId'123abc'执行请求,目前线程中有3封电子邮件.请求的响应是正确的,长度为3 response.messages.
- >然后我再发一封电子邮件作为回复此帖子,然后再次执行相同的请求.但是响应仍然是长度为3的旧响应response.messages.
- >尝试多次运行相同的请求但得到相同的响应.
- >然后清除此网址的浏览器缓存并再次请求,现在响应正确,长度为4 response.messages.
尝试在html页面中添加以下元标记,但不起作用:
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
Run Code Online (Sandbox Code Playgroud)
尝试添加随机数与页面网址和请求,但没有工作.
尝试使用gapi脚本链接添加随机数,但没有奏效 <script src="https://apis.google.com/js/client.js?onload=AuthIt&cacheBurster=123123123123"></script>
是否有任何代码可以禁用gapi请求缓存或任何其他方法来解决此问题?
这是我发布的上一个问题/答案的后续内容(如何使用Google电子邮件设置API和OAuth2 for Apps脚本库为Google Apps域中的用户设置电子邮件签名),但我正在创建一个新的问题,因为电子邮件设置API已被弃用,现在流程明显不同.
作为G Suite域的管理员,您如何使用Gmail API 以编程方式通过Google Apps脚本设置域中用户的电子邮件签名?
email google-apps google-apps-script gmail-api google-oauth2
我正在尝试使用gmail api阅读电子邮件.但是正文消息的格式是不可读的.
static void Main(string[] args)
{
UserCredential credential;
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/gmail-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Gmail API service.
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
UsersResource.MessagesResource.ListRequest request = service.Users.Messages.List("me");
IList<Message> messages = request.Execute().Messages;
if (messages != null && messages.Count > 0) …Run Code Online (Sandbox Code Playgroud) gmail-api ×10
email ×3
javascript ×2
android ×1
api ×1
c# ×1
gapi ×1
google-apps ×1
google-oauth ×1
ios ×1
php ×1
search ×1
swift ×1