我目前正在尝试测试新的Gmail REST API.
在API资源管理器中,可以使用OAuth 2.0授权请求并执行请求,即发送消息.
首先我授权.
我正在使用以下测试数据(当然我使用的是有效的to
电子邮件地址):
{
"raw": "c2VuZGluZyBhIG1haWwgdXNpbmcgR21haWwgUkVTVCBBUEk=",
"payload": {
"headers": [
{ "name": "to", "value": "info@something.com" },
{ "name": "from", "value": "taifunbaer@gmail.com" },
{ "name": "subject", "value": "Test Gmail REST API" }
],
"mimeType": "text/plain"
}
}
Run Code Online (Sandbox Code Playgroud)
我也得到了一个200 OK
和以下的结果,看起来很好.
{
"id": "146dee391881b35b",
"threadId": "146dee391881b35b",
}
Run Code Online (Sandbox Code Playgroud)
但是,邮件将无法成功发送,我可以nobody@gmail.com
在收件箱中找到一条消息;"An error occurred, your message has not been sent."
问题:
1.有人成功测试过吗?
2.我是否必须添加一些其他参数才能使其运行?
编辑:有2种不同的HTTP请求方法,
The …
检索包含此错误的邮件时,某个域的Gmail API失败:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 OK
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Delegation denied for <user email>",
"reason" : "forbidden"
} ],
"message" : "Delegation denied for <user email>"
}
Run Code Online (Sandbox Code Playgroud)
我正在使用OAuth 2.0和Google Apps域范围的授权来访问用户数据.域已授予应用程序的数据访问权限.
我在使用Gmail PHP API时遇到问题.
我想检索电子邮件的正文内容,但我只能检索有附件的电子邮件!我的问题是为什么?
到目前为止,这是我的代码:
// Authentication things above...
$client = getClient();
$gmail = new Google_Service_Gmail($client);
$list = $gmail->users_messages->listUsersMessages('me', ['maxResults' => 1000]);
while ($list->getMessages() != null) {
foreach ($list->getMessages() as $mlist) {
$message_id = $mlist->id;
$optParamsGet2['format'] = 'full';
$single_message = $gmail->users_messages->get('me', $message_id, $optParamsGet2);
$threadId = $single_message->getThreadId();
$payload = $single_message->getPayload();
$headers = $payload->getHeaders();
$parts = $payload->getParts();
//print_r($parts); PRINTS SOMETHING ONLY IF I HAVE ATTACHMENTS...
$body = $parts[0]['body'];
$rawData = $body->data;
$sanitizedData = strtr($rawData,'-_', '+/');
$decodedMessage = base64_decode($sanitizedData); //should display my body …
Run Code Online (Sandbox Code Playgroud) 我希望下面的代码能够发送电子邮件,但我只是得到了这个:
发生错误:调用POST时出错 https://www.googleapis.com/gmail/v1/users/me/messages/send:(400)错误请求
我得到一个200 OK
使用谷歌开发者控制台这里在底部.有帮助吗?
$client_id = '599901532082-js1r50n20q6n5mir9fo1g81qkj9kfn3j.apps.googleusercontent.com';
$service_account_name = '599901532082-js1r50n20q6n5mir9fo1g81qkj9kfn3j@developer.gserviceaccount.com';
$key_file_location = '/tmp/APIProject-cb6558ba6435.p12';
$client = new \Google_Client();
$client->setApplicationName("Client_Library_Examples");
$service = new \Google_Service_Gmail($client);
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new \Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/gmail.send', 'https://www.googleapis.com/auth/gmail.compose'),
$key
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
//check if you want the validity of this string at: http://www.komeil.com/toolbox/base64decoder
//it is web safe base64 encoded email
$mime = "RnJvbTogSm9obiBEb2UgPHRpcmVuZ2FyZmlvQGdtYWlsLmVzPiANClRvOiBNYXJ5IFNtaXRoIDx0aXJlbmdhcmZpb0BnbWFpbC5jb20-IA0KU3ViamVjdDogU2F5aW5nIEhlbGxvIA0KRGF0ZTogRnJpLCAyMSBOb3YgMTk5NyAwOTo1NTowNiAtMDYwMCANCk1lc3NhZ2UtSUQ6IDwxMjM0QGxvY2FsLm1hY2hpbmUuZXhhbXBsZT4NCg0KVGhpcyBpcyBhIG1lc3NhZ2UganVzdCB0byBzYXkgaGVsbG8uIFNvLCAiSGVsbG8iLg==";
$service = new \Google_Service_Gmail($client);
$msg = new \Google_Service_Gmail_Message(); …
Run Code Online (Sandbox Code Playgroud) 我正在创建Chrome扩展程序,并尝试在gMail撰写框的SEND按钮旁边添加一个小文本.
我正在使用MutationObserver来了解撰写框窗口何时出现.我通过观察一个带有类的元素来做这个,no
因为compose box元素被创建为这个元素(class no
)的子元素.
当用户单击撰写按钮并出现撰写框窗口时,我会使用该.after()
方法在SEND按钮旁边放置一个元素.发送按钮类名称是.gU.Up
.
这些是gMail的真正类名,也很奇怪.
以下是我使用的代码:
var composeObserver = new MutationObserver(function(mutations){
mutations.forEach(function(mutation){
mutation.addedNodes.forEach(function(node){
$(".gU.Up").after("<td> <div> Hi </div> </td>");
});
});
});
var composeBox = document.querySelectorAll(".no")[2];
var config = {childList: true};
composeObserver.observe(composeBox,config);
Run Code Online (Sandbox Code Playgroud)
问题是我经常遇到以下错误:
Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?我已经尝试了很多东西,并在这里查看了其他答案,但仍然无法摆脱这个错误.
这是我的manifest.json文件:
{
"manifest_version": 2,
"name": "Gmail Extension",
"version": "1.0",
"browser_action": {
"default_icon": "icon19.png",
"default_title": "Sales Analytics Sellulose"
},
"background": {
"scripts": ["eventPage.js"], …
Run Code Online (Sandbox Code Playgroud) javascript gmail google-chrome-extension mutation-observers gmail-api
有没有办法使用GMail api以html格式检索邮件正文?
我已经通过了message.get
..试图改变文档format
PARAMS到full
,minimal
和raw
.但是id并没有帮助.它返回邮件正文.
格式值说明:
"full":返回有效内容字段中已解析的电子邮件内容,并且不使用原始字段.(默认)
"minimal":仅返回标识符和标签等电子邮件元数据,不返回电子邮件标题,正文或有效内容.
"raw":以字符串形式返回原始字段中的整个电子邮件内容,并且不使用有效内容字段.这包括标识符,标签,元数据,MIME结构和小体部分(通常小于2KB).
我们不能简单地以html格式获取邮件正文,或者是否有其他方法可以做到这一点,以便当他们在我的应用程序或GMail中看到邮件时,屏幕上显示的邮件差别很小?
看起来这里可能存在版本不匹配问题.我该怎么办呢?
我尝试用pip更新六个,但这没有做任何事情.
这是我看到的错误:
Traceback (most recent call last):
File "./quickstart.py", line 27, in <module>
credentials = run(flow, STORAGE, http=http)
File "/Library/Python/2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Python/2.7/site-packages/oauth2client/old_run.py", line 120, in run
authorize_url = flow.step1_get_authorize_url()
File "/Library/Python/2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 1827, in step1_get_authorize_url
return _update_query_params(self.auth_uri, query_params)
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 435, in _update_query_params
parts = urllib.parse.urlparse(uri)
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlparse'
Run Code Online (Sandbox Code Playgroud) 当我尝试使用服务帐户授权gmail api时,我收到以下错误
"客户端未经授权使用此方法检索访问令牌"
static async Task MainAsync()
{
sstageEntities db = new sstageEntities();
//UserCredential credential;
Dictionary<string, string> dictionary = new Dictionary<string, string>();
String serviceAccountEmail =
"xxx.iam.gserviceaccount.com";
var certificate = new X509Certificate2(
AppDomain.CurrentDomain.BaseDirectory +
"xxx-8c7a4169631a.p12",
"notasecret",
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
//string userEmail = "user@domainhere.com.au";
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
User = "xxx@xxx.com",
Scopes = new[] { "https://mail.google.com/" }
}.FromCertificate(certificate)
);
// Create Gmail API service.
var gmailService = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
}); …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个应用,我正在使用Gmail API从Gmail中获取电子邮件.
在电子邮件中,有1个图像直接嵌入电子邮件正文(内联图像不附件).我能够提取text/html部分,并且它在浏览器上正确显示,但是在内嵌图像的情况下,它显示了破碎的图像.
在图片标签中,它显示为
<img src=\"cid:ii_jfi5vwc30_1628627122d12121\" width=\"454\" height=\"255\">
Run Code Online (Sandbox Code Playgroud)
它在src中提供内容id而不是image url .有谁知道我应该如何使用浏览器页面中的cid显示内嵌图像.我该如何从cid获取base64格式的图像?
我们正在创建一个以Ionic框架作为前端和Ruby on Rails作为后端的应用程序.我们可以在我们的应用中关联Gmail帐户.帐户链接工作正常,我们从前端获取serverAuthCode,然后使用它获取刷新令牌,我们可以在第一次尝试时使用该刷新令牌获取电子邮件.但在几秒钟内,它就会过期或被撤销.得到以下问题:
Signet::AuthorizationError (Authorization failed. Server message:
{
"error" : "invalid_grant",
"error_description" : "Token has been expired or revoked."
})
Run Code Online (Sandbox Code Playgroud)
看起来,刷新令牌本身就会在几秒钟内到期.有没有人知道如何解决它?
更新:
现有代码如下所示:
class User
def authentication(linked_account)
client = Signet::OAuth2::Client.new(
authorization_uri: 'https://accounts.google.com/o/oauth2/auth',
token_credential_uri: Rails.application.secrets.token_credential_uri,
client_id: Rails.application.secrets.google_client_id,
client_secret: Rails.application.secrets.google_client_secret,
scope: 'https://www.googleapis.com/auth/gmail.readonly, https://www.googleapis.com/auth/userinfo.email, https://www.googleapis.com/auth/userinfo.profile',
redirect_uri: Rails.application.secrets.redirect_uri,
refresh_token: linked_account[:refresh_token]
)
client.update!(access_token: linked_account.token, expires_at: linked_account.expires_at)
return AccessToken.new(linked_account.token) unless client.expired?
auth.fetch_access_token!
end
def get_email(linked_account)
auth = authentication(linked_account)
gmail = Google::Apis::GmailV1::GmailService.new
gmail.client_options.application_name = User::APPLICATION_NAME
gmail.authorization = AccessToken.new(linked_account.token)
query = "(is:inbox OR is:sent)"
gmail.list_user_messages(linked_account[:uid], …
Run Code Online (Sandbox Code Playgroud) gmail-api ×10
gmail ×2
google-api ×2
google-oauth ×2
oauth-2.0 ×2
php ×2
python ×2
c# ×1
html ×1
javascript ×1
rest ×1