标签: google-contacts-api

自动将电子邮件地址从表单添加到联系人组

我负责即将召开的学生会议,并在Google云端硬盘上创建了一个注册表单,其中一个"问题"是注册人的电子邮件地址.在Google云端硬盘中,所有电子邮件地址都会整理到一列中.

有没有办法自动将此列电子邮件地址同步到指定的联系人组,以便其他所有注册人的电子邮件地址将在组中更新?这将有助于我在会议更新时回复他们.

非常感谢您的帮助 :)

forms email google-contacts-api google-drive-api

5
推荐指数
0
解决办法
132
查看次数

通过OAuth 2.0和私钥(即服务帐户)访问Google通讯录Api

我目前正在通过OAuth 2.0和所谓的服务帐户实施对Google通讯录的访问.为普通用户生成服务帐户,例如"My.Name@gmail.com".

生成OAuth 2.0凭据的代码是:

public static GoogleCredential getCredentials() throws GeneralSecurityException, IOException {
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(SingleUserCredentials.SERVICE_ACCOUNT_EMAIL)
            .setServiceAccountScopes("https://www.google.com/m8/feeds")
            .setServiceAccountPrivateKeyFromP12File(new File(SingleUserCredentials.SERVICE_ACCOUNT_PKCS12_FILE_PATH))
            .build();
    credential.refreshToken();
    return credential;
}
Run Code Online (Sandbox Code Playgroud)

然后我试图通过以下方式检索联系人:

    ContactsService myService = new ContactsService(
            "myApp");

    myService.setOAuth2Credentials(getCredentials());

    URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
    Query myQuery = new Query(feedUrl);
    ContactFeed resultFeed = myService.query(myQuery, ContactFeed.class);
    // Print the results

    for (ContactEntry entry : resultFeed.getEntries()) {
        System.out.println(entry.getName().getFullName().getValue());
        System.out.println("Updated on: " + entry.getUpdated().toStringRfc822());
    }
Run Code Online (Sandbox Code Playgroud)

问题是我的帐户中没有任何一个联系人.Feed始终为空.没有错误.没有.

通过相同的方法访问Google Apps托管域时,它可以正常运行.

我想知道在使用p12密钥文件和服务帐户时,Contacts Api是否支持普通(也称为@ gmail.com)帐户的OAuth 2.0.

gdata-api google-api google-contacts-api oauth-2.0 service-accounts

5
推荐指数
1
解决办法
4822
查看次数

Google通讯录API - 无法刷新访问令牌

我们在OAuth2中使用Google Contacts API:

credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport())
        .setJsonFactory(new JacksonFactory())
        .setClientSecrets(OAuth2ClientId(), OAuth2ClientSecret())
        .addRefreshListener(new CredentialRefreshListener() {...});

myService = new ContactsService("My-App");
myService.setOAuth2Credentials(credential);
Run Code Online (Sandbox Code Playgroud)

并且我们经常收到GData库无法处理的"401 Unauthorized"响应.AuthenticationException在WWW-Authenticate标头丢失时抛出NPE .

Caused by: java.lang.NullPointerException: No authentication header information
        at com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96) ~[gdata-core-1.0-1.47.1.jar:na]
        at com.google.gdata.util.AuthenticationException.<init>(AuthenticationException.java:67) ~[gdata-core-1.0-1.47.1.jar:na]
        at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:608) ~[gdata-core-1.0-1.47.1.jar:na]
        at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564) ~[gdata-core-1.0-1.47.1.jar:na]
        at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560) ~[gdata-core-1.0-1.47.1.jar:na]
        at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538) ~[gdata-core-1.0-1.47.1.jar:na]
        at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536) ~[gdata-core-1.0-1.47.1.jar:na]
        at com.google.gdata.client.Service.getFeed(Service.java:1135) ~[gdata-core-1.0-1.47.1.jar:1.47.1]
        at com.google.gdata.client.Service.getFeed(Service.java:1077) ~[gdata-core-1.0-1.47.1.jar:1.47.1]
        at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:676) ~[gdata-core-1.0-1.47.1.jar:1.47.1]
        at com.google.gdata.client.Service.query(Service.java:1237) ~[gdata-core-1.0-1.47.1.jar:1.47.1]
        at com.google.gdata.client.Service.query(Service.java:1178) ~[gdata-core-1.0-1.47.1.jar:1.47.1]
Run Code Online (Sandbox Code Playgroud)

我们设法添加了一个在这个NPE上尝试令牌刷新的包装器.它有所帮助,但是当刷新失败时仍有很多情况:

credential.refreshToken() == false
Run Code Online (Sandbox Code Playgroud)

当我们refreshToken()在调试器中运行时,我们看到它executeRefreshToken()在没有异常的情况下执行但是tokenResponse==null被返回.结果refreshToken() …

google-api google-contacts-api google-data-api google-oauth

5
推荐指数
1
解决办法
2106
查看次数

获取令牌,存储它,如果在ruby中使用oauth2 gem过期则刷新它

我正在编写脚本以使用谷歌联系人api gem获取谷歌联系人.我可以使用以下代码成功访问令牌:

require 'rubygems'
require 'launchy'
require 'oauth2'
require 'googlecontacts'
require 'google_contacts_api'

# Get your credentials from the console
CLIENT_ID = 'your Id'
CLIENT_SECRET = 'your Secret'
OAUTH_SCOPE = 'https://www.google.com/m8/feeds'
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'

client = OAuth2::Client.new(CLIENT_ID, CLIENT_SECRET,site: 'https://accounts.google.com',token_url: '/o/oauth2/token', authorize_url: '/o/oauth2/auth')
url = client.auth_code.authorize_url(scope: OAUTH_SCOPE, redirect_uri: REDIRECT_URI)
Launchy.open(url)
$stdout.write  "Enter authorization code: "
code = gets.chomp
token = client.auth_code.get_token(code, :redirect_uri => REDIRECT_URI)
Run Code Online (Sandbox Code Playgroud)

问题:

我知道这不是最好的方法,因为它很累.每次我运行脚本时,用户都会给出访问说明.此外,我还必须手动将令牌从浏览器粘贴到终端.

题:

如何能够存储检索到的令牌,当它过期时如何刷新它?

google-contacts-api oauth-2.0 ruby-2.1

5
推荐指数
1
解决办法
7099
查看次数

谷歌与联系人API的People API

在尝试使用用户的Google帐户获取联系人时,我在使用人员API后面临一些问题.它只返回所有列出的几个电子邮件地址.访问令牌和所有范围都已正确设置.以下代码:

People peopleService = new People.Builder(httpTransport, jsonFactory, credential)
                    .build();
ListConnectionsResponse response = peopleService.people().connections().list("people/me")
                    .setPageSize(500).setSortOrder("FIRST_NAME_ASCENDING")
                    .setAccessToken(tokenResponse.getAccessToken())
                    .setAlt("json")
                    .setRequestMaskIncludeField("person.names,person.emailAddresses,person.phoneNumbers")
                    . execute();
   connections = response.getConnections();
Run Code Online (Sandbox Code Playgroud)

如果我使用谷歌的联系API,那么我将获得更多的电子邮件地址而不是人们.联系API的代码:

URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
    ContactFeed resultFeed = myService.getFeed(feedUrl, ContactFeed.class);

    // Print the results
    System.out.println(resultFeed.getTitle().getPlainText());
    for (ContactEntry entry : resultFeed.getEntries()) {
          ....
          .....
          .......
 }
Run Code Online (Sandbox Code Playgroud)

我想知道他们两者之间是否有任何差异,我必须使用哪一个以获得更好的结果,或者我错过了什么.请建议.谢谢..!!

android google-contacts-api android-contacts google-people

5
推荐指数
1
解决办法
1300
查看次数

Google API Contacts v.3,PHP:向群组添加联系人

我成功地设法与cURL创建了一个新的联系人,但是当我想为这个联系人添加组成员身份时,我得到400错误.我已阅读此文档 并提出相同的请求,但它无效.我究竟做错了什么?谢谢你的任何想法!

这就是我用组信息创建XML的方法:

$doc = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;

$entry = $doc->createElement('entry');
$entry->setAttribute('gd:etag', $etag);
$doc->appendChild($entry);

$category = $doc->createElement('category');
$category->setAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
$category->setAttribute('term', 'http://schemas.google.com/contact/2008#contact');
$entry->appendChild($category);

$id = $doc->createElement('id', 'http://www.google.com/m8/feeds/contacts/default/base/'.$idgmail);
$entry->appendChild($id);

$updated = $doc->createElement('updated', $update_info);
$entry->appendChild($updated);

// Add group info (My Contacts)

$group = $doc->createElement('gContact:groupMembershipInfo');
$entry->appendChild($group);
$group->setAttribute('deleted', 'false');
$group->setAttribute('href', 'http://www.google.com/m8/feeds/groups/default/base/6');

// Add another group info

$group = $doc->createElement('gContact:groupMembershipInfo');
$entry->appendChild($group);
$group->setAttribute('deleted', 'false');
$group->setAttribute('href', 'http://www.google.com/m8/feeds/groups/default/base/'.$my_group_id);

$group_info = $doc->saveXML();
Run Code Online (Sandbox Code Playgroud)

这是我的cURL:

$url = 'https://www.google.com/m8/feeds/contacts/default/full/'.$idgmail.'/';

$headers = array(
'Host: www.google.com',
'Gdata-version: 3.0',
'Content-length: '.strlen($group_info),
'Content-type: …
Run Code Online (Sandbox Code Playgroud)

php xml curl google-contacts-api

4
推荐指数
1
解决办法
3277
查看次数

针对n个热门联系人的Google通讯录API查询

有没有办法只查询n个热门联系人?例如:

http://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=50&popular=true
Run Code Online (Sandbox Code Playgroud)

这将只返回50个热门联系人.(比如在gmail联系人中有20个热门联系人).

如果没有办法查询,有没有办法检查哪些联系人最受欢迎.热门=更多电子邮件活动与他们然后与他人.

谢谢.

google-api google-contacts-api

4
推荐指数
1
解决办法
824
查看次数

在Ruby上访问Google Contacts API

我很难访问Google Contacts API.

首先我尝试了google-api-ruby-clientgem,但事实证明它不支持Contacts API.

接下来的镜头是google_contacts_api 宝石,但我很难得到一个oauth_access_token_for_useroAuth2 宝石.当遵循oAuth2指令时,我不知道放入什么authorization_code_valueBasic some_password.

我尝试了以下方法:

require 'oauth2'
client = OAuth2::Client.new(ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'], :site => 'http://localhost:9292')
=> #<OAuth2::Client:0x007fcf88938758 @id="blabla.apps.googleusercontent.com", @secret="blabla", @site="http://localhost:9292", @options={:authorize_url=>"/oauth/authorize", :token_url=>"/oauth/token", :token_method=>:post, :connection_opts=>{}, :connection_build=>nil, :max_redirects=>5, :raise_errors=>true}>

client.auth_code.authorize_url(:redirect_uri => 'http://localhost:9292')
=> "http://localhost:9292/oauth/authorize?client_id=blabla.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A9292&response_type=code"

token = client.auth_code.get_token('authorization_code_value', :redirect_uri => 'http://localhost:9292', :headers => {'Authorization' => 'Basic some_password'})
=> Faraday::ConnectionFailed: Connection refused - connect(2) for "localhost" port 9292
Run Code Online (Sandbox Code Playgroud)

如果有人能给我详细的逐步说明如何访问API,我将不胜感激.

ruby api ruby-on-rails google-api google-contacts-api

4
推荐指数
1
解决办法
2028
查看次数

Google Contact API返回无效的XML文档错误

使用Google通讯录api添加联系人时,我一直收到状态代码400,其中包含无效的XML文档错误。

如果删除以下行,则添加联系人api成功。但是,这种行为不是我想要的。我想将其添加到基本组6。

<gContact:groupMembershipInfo deleted="false"
          href="http://www.google.com/m8/feeds/groups/binthi123@gmail.com/base/6"/>
Run Code Online (Sandbox Code Playgroud)

以下是添加新的联系人api发布请求的正文:

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">
  <atom:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact" />
  <gd:name>
    <gd:givenName>1234567890</gd:givenName>
  </gd:name>
  <gd:phoneNumber rel="http://schemas.google.com/g/2005#mobile" primary="true">
    ${phone_number}
  </gd:phoneNumber>
  <gContact:groupMembershipInfo deleted="false" href="http://www.google.com/m8/feeds/groups/binthi123@gmail.com/base/6" />
</atom:entry>
Run Code Online (Sandbox Code Playgroud)

google-contacts-api

4
推荐指数
1
解决办法
437
查看次数

google oauth2:为Web服务器应用程序上的授权用户重新获取refresh_token

我在网络服务器上使用oauth2,流程完美无缺(https://developers.google.com/accounts/docs/OAuth2WebServer).

但是,我有一些情况需要重新获取refresh_token(比方说,例如,refresh_token已经"丢失").

在这种情况下,当我再次进入第1阶段和第2阶段时,我只获得access_token而不是refresh_token.如果用户通过他的Google帐户控制台撤消权限并再次进入第1阶段和第2阶段,我将获得一个新的refresh_token.

这是已知的oauth2行为吗?有没有办法强制一个新的refresh_token或再次获得相同的刷新?

google-contacts-api oauth-2.0

3
推荐指数
1
解决办法
3052
查看次数