如何以编程方式向Google进行身份验证?现在的ClientLogin(https://developers.google.com/accounts/docs/AuthForInstalledApps)已过时,我们如何能够执行编程认证,以与谷歌的OAuth2?
使用ClientLogin,我们可以 使用电子邮件和密码参数向https://www.google.com/accounts/ClientLogin发送帖子, 并获取身份验证令牌.
使用OAuth2我找不到解决方案!
#我的应用程序是一个java后台进程.我看到,点击此链接:developers.google.com/accounts/docs/OAuth2InstalledApp#refresh,如何使用刷新的令牌获取新的访问令牌.
问题是,当我有一个新的有效访问令牌时,我找不到一个关于如何实例化Analytics对象(例如)来执行查询的java示例
这是我的代码在调用"execute()"时返回401无效凭据:
public class Test {
static final String client_id = "MY_CLIENT_ID";
static final String client_secret = "MY_SECRET";
static final String appName = "MY_APP";
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
static String access_token = "xxxx";
static String refreshToken = "yyyyy";
public static void main (String args[]){
try {
GoogleCredential credential =
new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setClientSecrets(client_id, client_secret).build();
credential.setAccessToken(access_token);
credential.setRefreshToken(refreshToken); …Run Code Online (Sandbox Code Playgroud) 我对 Facebook Oauth access_token 端点有一个奇怪的问题:
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
Run Code Online (Sandbox Code Playgroud)
此处的文档(在“场景 3”中)说:“如果在该用户仍然存在有效的长期用户 access_token 时进行调用,则第二次调用返回的用户 access_token 可能相同或可能已更改,但在任何一种情况下,到期时间都将设置为较长的到期时间。”
如果我获得了一个有效的长期用户 access_token,这个端点会返回与我已经拥有的相同的访问令牌,并且也会返回 expires 参数,但仅限于很短的时间。因此,如果我在一段时间后(例如几个小时)重复对上述相同的调用并使用相同的 access_token 指向它,它只会返回没有 expires 参数的 access_token 。...所以我无法确定我的 access_token 何时到期。请注意,返回的 access_token 仍然有效并且运行良好。
你遇到过同样的问题吗?你有什么建议吗?谢谢!
facebook oauth facebook-graph-api facebook-authentication facebook-access-token
我无法找到使用java从pub/sub读取消息的方法.
我在我的pom中使用这个maven依赖
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>0.17.2-alpha</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我实现了这个main方法来创建一个新主题:
public static void main(String... args) throws Exception {
// Your Google Cloud Platform project ID
String projectId = ServiceOptions.getDefaultProjectId();
// Your topic ID
String topicId = "my-new-topic-1";
// Create a new topic
TopicName topic = TopicName.create(projectId, topicId);
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
topicAdminClient.createTopic(topic);
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码效果很好,实际上,我可以看到我使用谷歌云控制台创建的新主题.
我实现了以下主要方法来向我的主题写一条消息:
public static void main(String a[]) throws InterruptedException, ExecutionException{
String projectId = ServiceOptions.getDefaultProjectId();
String topicId = "my-new-topic-1";
String payload = "Hellooooo!!!";
PubsubMessage pubsubMessage =
PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8(payload)).build(); …Run Code Online (Sandbox Code Playgroud)