我正在使用Java SDK Android Publisher v2和Oauth2 v2.一旦我创建了服务帐户,我就获得了一个Google Play Android Developer带有客户端ID,电子邮件,私钥等的服务帐户JSON .我试图环顾四周并找出如何创建凭据以便我使用AndoirdPublisher服务来获取信息我的Android应用程序的用户订阅,权利等,并将此信息存储在我们的后端服务器上.
我正在努力弄清楚如何解决这个问题.到目前为止,我见过的所有文档都没有帮助创建GoogleCredential使用下载的JSON.
例如,有这个文档,但它只提到P12文件,而不是JSON.如果可能,我想避免使用P12,因为我有多个客户端,我想将这个JSON保存在某种数据库中,然后用它来为每个客户端创建凭据.
只是为了澄清我正在尝试创建这里描述的GoogleCredential对象,
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.sqladmin.SQLAdminScopes;
// ...
String emailAddress = "123456789000-abc123def456@developer.gserviceaccount.com";
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(emailAddress)
.setServiceAccountPrivateKeyFromP12File(new File("MyProject.p12"))
.setServiceAccountScopes(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN))
.build();
Run Code Online (Sandbox Code Playgroud)
但是,不是像这样使用P12文件设置服务帐户setServiceAccountPrivateKeyFromP12File(),我想使用带有相同信息的JSON,并在创建服务帐户时生成.
android subscription google-api-java-client in-app-billing google-play-services
这是我的Gmail服务配置/工厂类:
import java.io.File;
import java.io.IOException;
import java.security.GeneralSecurityException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.gmail.Gmail;
import com.google.api.services.gmail.GmailScopes;
public class GmailServiceFactoryBean {
private @Autowired Environment env;
private final NetHttpTransport transport;
private final JacksonFactory jacksonFactory;
public GmailServiceFactoryBean() throws GeneralSecurityException, IOException {
this.transport = GoogleNetHttpTransport.newTrustedTransport();
this.jacksonFactory = JacksonFactory.getDefaultInstance();
}
public Gmail getGmailService() throws IOException, GeneralSecurityException {
return new Gmail.Builder(transport, jacksonFactory, getCredential())
.setApplicationName(env.getProperty("gmail.api.application.name")).build();
}
private HttpRequestInitializer getCredential() throws IOException, GeneralSecurityException {
File p12File = …Run Code Online (Sandbox Code Playgroud) 我想在没有手动浏览器身份验证的情况下登录我的流星服务器程序。所以认证必须全部自动化;我根本不想要用户干预/互动。我在这里遇到了答案,但它是在 Java 中的,我不知道它是否有效。有人可以在meteor.js 中提供答案。如果答案在 node.js 中并且可以在流星中工作,那也很好。
最好我想在后端运行这个流星代码,作为使用 msavin /SteveJobs pacjage 的工作的一部分。
是否可以在不使用模拟的情况下使用Google Credentials for GMAIL REST API?
在GMAIL REST API的许多示例中,我看到必须使用与域和Google APPS关联的模拟帐户.我只想使用GMAIL REST API api服务器到服务器:
FE:
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(serviceAccountUserEmail)
**.setServiceAccountUser("myuser@mydomain.com)**
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(
new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
.build();
Run Code Online (Sandbox Code Playgroud)
问题是,我没有任何域名,我只使用GMAIL帐户...但我没有任何方式授权,例如:MyMainGmailAcccoun@gmail.com
servive acccount id 4xxxxxxxxxxxxxq@developer.gserviceaccount.com";是使用MyMainGmailAcccoun@gmail.com创建的" 客户帐户"
这没有任何意义,我不想冒充其他域名的其他帐户,我也没有任何办法来authozize MyMainGmailAcccoun@gmail.com.
只是有效,如果您有一个帐户来冒充与Google Apps相关的其他域名,并获得Google Apps ...您需要一个域名.
任何建议?
我正在尝试使用服务帐户在JUnit测试中从gmail发送电子邮件.
我有这个测试:
@Test
public void testGmailCredential() throws GeneralSecurityException, URISyntaxException {
try {
InputStream is = getClass().getClassLoader().getResourceAsStream("myProject.json");
GoogleCredential credential = GoogleCredential.fromStream(is).createScoped(GmailScopes.all());
System.out.println("Scopes are " + credential.getServiceAccountScopesAsString());
Gmail gmailService = new Gmail.Builder(getHttpTransport(), JSON_FACTORY, credential)
.setApplicationName("WHAT SHOULD THIS VALUE BE?")
//.setHttpRequestInitializer(credential)
.build();
InternetAddress to = new InternetAddress("myemail@myurl.com", "Tom Catfish");
InternetAddress from = new InternetAddress("myServiceAccountId@xxxxxxxxxx.iam.gserviceaccount.com", "Some Name");
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
email.setFrom(from);
email.addRecipient(javax.mail.Message.RecipientType.TO, to);
email.setSubject("Subject here");
email.setText("body here");
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 API 获取 gsuite 警报。我已经根据他们的文档创建了一个服务帐户,并将该服务帐户分配给我的谷歌云功能。
我不想使用环境变量或上传凭据以及源代码,但我想利用函数使用的默认服务帐户。
from googleapiclient.discovery import build
def get_credentials():
# if one knows credentials file location(when one uploads the json credentials file or specify them in environment variable) one can easily get the credentials by specify the path.
# In case of google cloud functions atleast I couldn't find it the path as the GOOGLE_APPLICATION_CREDENTIALS is empty in python runtime
# the below code work find if one uncomments the below line
#credentials = ServiceAccountCredentials.from_json_keyfile_name(key_file_location) …Run Code Online (Sandbox Code Playgroud) python service-accounts google-cloud-platform google-cloud-functions google-python-api
我已经阅读了教程并且已经看了两天的例子,但没有成功.我想在NodeJS环境中使用Google Apps Gmail帐户发送电子邮件,但是,我得到400了Google API的回复:
{[Error: Bad Request]
code: 400,
errors:
[{
domain: 'global',
reason: 'failedPrecondition',
message: 'Bad Request'
}]
}
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所做的:
Domain Wide Delegation服务帐户JSON格式下载服务帐户的密钥API Manager> Credentials我创造了OAuth 2.0 client ID 在Google Apps管理控制台中:
Security> Advanced Settings> Manage API client access我已经添加了Client ID从步骤4上述Client ID这是尝试发送电子邮件的代码:
const google = require('googleapis');
const googleKey = require('./google-services.json');
const jwtClient = new …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个非常简单的脚本来自动执行我自己的 GMAIL 帐户上的一些操作
谷歌上使用 GMAIL API 的所有教程都侧重于访问其他人的数据,因此它正确地通过浏览器中的 OAuth 访问请求,但我正在尝试阅读我自己的邮件,并且我正在使用 ubuntu 服务器,所以我没有访问图形浏览器。
我怎样才能做到这一点?
请不要回答说“不可能,谷歌要求它bla bla bla安全”我过去做过类似的事情我只是没有以前的代码......
我相信,如果我创建一个服务帐户并向该帐户授予一些权限,我将能够执行此操作,但我无法找到我需要授予哪些权限或我当前缺少什么步骤
public static Gmail createGmailServiceClient(final List<String> scopes, final String jsonCredentials) throws GeneralSecurityException, IOException {
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
return new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, GoogleCredential.fromStream(new ByteArrayInputStream(jsonCredentials.getBytes())).createScoped(scopes)).build();
}
Gmail gmail = SimpleGmail.createGmailServiceClient(Arrays.asList(GmailScopes.GMAIL_READONLY), json);
ListMessagesResponse mails = gmail.users().messages().list("me").execute();
System.out.println(mails);
Run Code Online (Sandbox Code Playgroud)
但是当这样做时我得到
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Precondition check failed.",
"reason" : "failedPrecondition"
} ],
"message" : "Precondition check failed.",
"status" …Run Code Online (Sandbox Code Playgroud) gmail ×4
java ×4
gmail-api ×3
google-apps ×2
node.js ×2
android ×1
email ×1
google-api ×1
google-oauth ×1
jwt ×1
meteor ×1
oauth-2.0 ×1
python ×1
rest ×1
spring ×1
subscription ×1