标签: google-api-client

创建Google联系人 - >为什么只在新联系人中插入"NAME"?

以下是我提出的要求: -

    // create new entry
$doc = new DOMDocument();
$doc->formatOutput = true;

$entry = $doc->createElement('atom:entry');
$entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:atom', 'http://www.w3.org/2005/Atom');
$entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', 'http://schemas.google.com/g/2005');
$doc->appendChild($entry);

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

// add name element
$name = $doc->createElement('gd:name');
$entry->appendChild($name);
$givenName = $doc->createElement('gd:givenName', $_POST['fname']);
$familyName = $doc->createElement('gd:familyName', $_POST['lname']);
$fullName = $doc->createElement('gd:fullName', $_POST['fname'] . $_POST['lname']);
$name->appendChild($givenName);
$name->appendChild($familyName);
$name->appendChild($fullName);

$content = $doc->createElement('atom:content', 'Notes');
$content->setAttribute('type', 'text');
$entry->appendChild($content);
// add email element
$email = $doc->createElement('gd:email');
$entry->appendChild($email);
$email->setAttribute('address', $_POST['email_id']);
$email->setAttribute('displayName', $_POST['fname']);
$email->setAttribute('primary', 'true');
$email->setAttribute('rel', 'http://schemas.google.com/g/2005#work'); …
Run Code Online (Sandbox Code Playgroud)

php oauth google-api oauth-2.0 google-api-client

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

Google+ JavaScript API:如何检测用户登录状态?

我已经部署了Google+登录按钮,现在我必须提供注销按钮,在此之前,我需要知道用户是否仍然已登录,然后我可以通过该按钮显示或隐藏此按钮.

我找到了这个文档:gapi.auth.checkSessionState(sessionParams,callback):https: //developers.google.com/+/web/api/javascript?hl = en #gapiauthchecksessionstatesessionparams_callback

有人可以演示如何使用它吗?

非常感谢.

google-api-client google-plus

4
推荐指数
2
解决办法
2万
查看次数

如何通过 GMAIL API 发送带有 BCC 标头的电子邮件?

如何通过 GMAIL API 使用 BCC 发送电子邮件?我向 TO 或 CC 发送电子邮件,但 BCC 不起作用。我使用Base64.urlsafe_encode64(email.to_s)此代码创建没有 BCC 的字符串。我的工作代码示例:

    email = Mail.new
    email.date = Time.now
    email.subject = subject
    email.to = email_array_to_email_to(to)
    email.cc = email_array_to_email_to(cc)
    email.bcc = email_array_to_email_to(bcc)
    email.reply_to = email_array_to_email_to(reply_to)
    email.html_part do
      body message
    end
    request = {
        api_method: @google_api.users.messages.to_h['gmail.users.messages.send'],
        parameters: { userId: 'me' },
        body_object: {
            raw: Base64.urlsafe_encode64(email.to_s)
        },
    }
Run Code Online (Sandbox Code Playgroud)

我是否必须再次调用 GMAIL API 并使用线程 ID 和密件抄送作为 TO 发送此电子邮件?我使用google-api-client 0.7.1

编辑:邮件对象:

#<Mail::Message:70336725981360,
Multipart: true,
Headers: <Date: Tue,
01 Dec 2015 14:09:08 +0100>, …
Run Code Online (Sandbox Code Playgroud)

ruby gmail ruby-on-rails google-api-client gmail-api

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

使用 Google-Drive-API 移动文件

是否可以通过 python 的 googleapiclient 模块显式移动文件?我想创建以下函数,给定文件、原始路径和目标路径:

def move_file(service, filename, init_drive_path, drive_path, copy=False):
    """Moves a file in Google Drive from one location to another.

    service: Drive API service instance.
    filename (string): full name of file on drive
    init_drive_path (string): initial file location on Drive
    drive_path (string): the file path to move the file in on Drive
    copy (boolean): file should be saved in both locations

    Returns nothing.
    """
Run Code Online (Sandbox Code Playgroud)

目前我一直通过手动下载文件然后将其重新上传到所需位置来执行此操作,但是这对于大文件来说并不实用,无论如何似乎都是一种解决方法。

这是google-drive-api 上可用方法的文档


编辑请参阅下面的解决方案:

python google-api-client google-api-python-client

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

how to change the package name of an app in android studio linked to firebase

I created a android app which is linked to Firebase . But i forgot to give package name so by default it took "com.example.abc.appname" . Here the problem is when i am uploading app in google playstore its not accepting release apk with generated with that file name.

  1. So how to change package name without getting any conflicts as it is linked to firebase.
  2. google plus 登录也存在问题,它在调试模式下工作正常,但无法通过发布模式进行身份验证。我没有找到任何解决方案。应用程序处于发布阶段,我正面临这些问题。

android google-api-client firebase android-studio

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

Google服务帐户和工作表权限

我有一个 Java 后端(spring + google-oauth-client),它应该能够访问 Google.sheets 并从那里解析一些数据。

首先,我在本地后端部署上实现了常规的“三足”OAuth 2.0 身份验证,它工作得很好,但由于后端将部署在没有任何浏览器的云中,因此这不是最好的选择。

所以我决定使用服务帐户OAuth流程:创建谷歌服务帐户并重构我的代码以使用它而不是AuthCodeFlow,但我看到403 Forbidden“调用者没有权限”。据我所知,服务帐户不是谷歌的“我”,所以我必须让它访问“我的”帐户上的该工作表,但我不能这样做,因为我公司的政策禁止与他人共享文档我们的域,并且由于服务帐户具有 @myprject.iam.gserviceaccount.com 域,我无法授予对其的访问权限。

也许有一种方法可以解决这个问题,因为该服务帐户是从我的帐户创建的,该帐户拥有该工作表的所有者访问权限?如果不是,在这种情况下(无需用户参与)服务器到服务器 OAuth 的最佳方法是什么?

ps 我可以尝试与我的服务台联系,询问他们是否可以将此 gserviceaccount.com 添加到白名单等,但这将花费相当多的时间,而且结果也不能保证。

谢谢!

google-api oauth-2.0 google-api-client google-oauth service-accounts

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

Google Analytics:用户对此配置文件没有足够的权限

我无法从 Rails 访问 Google Analytics API。即使我已经设置了服务帐户,我仍然获得足够的权限。

我创建了一个服务帐户:

  • 转到 console.developers.google.com/iam-admin/serviceaccounts 中的项目
  • 我转到服务帐户 > 创建服务帐户
  • 然后选择帐户并添加密钥。这将使用服务帐户下载一个 JSON 文件。

拥有服务帐户并拥有秘密 JSON 文件和电子邮件后。然后我去谷歌分析:

  • 进入管理 > 选择物业 > 物业用户管理 > 添加用户
  • 复制服务帐户电子邮件并选择阅读和分析

一旦我有了这个,几乎可以使用以下代码: https: //gist.github.com/CoryFoy/9edf1e039e174c00c209e930a1720ce0来获取报告。

但我不断得到forbidden: User does not have sufficient permissions for this profile。即使当我尝试获取 access_token 并在 javascript 中使用它时:

gapi.analytics.auth.authorize({
  serverAuth: {
    access_token: 'accessToken'
  }
});
Run Code Online (Sandbox Code Playgroud)

我得到:

error:{
  code: 403
  errors: [  
    {  
      domain: "global"
      message: "User does not have sufficient permissions for this profile."
      reason: "insufficientPermissions"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?这曾经有效,我从来没有遇到过问题,但由于某种原因它停止工作了。任何指导将不胜感激。

谢谢你! …

javascript google-analytics ruby-on-rails google-api-client google-analytics-4

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

Google API 错误 - 无法根据请求确定客户端 ID

我正在使用 google-api-php-client 从客户端 0auth 流请求访问令牌,但它返回错误“无法从请求确定客户端 ID”。

我的代码如下。

我的 client_secret.json:

    "web": {
        "client_id":"123",
        "project_id":"1234",
        "auth_uri":"https://accounts.google.com/o/oauth2/auth",
        "token_uri":"https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
        "client_secret":"123456789",
        "redirect_uris":[
            "http://localhost:7777/v1/oauth2callback"
        ],
        "javascript_origins":[
            "http://localhost:7777"
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

我的身份验证 URL 创建:

    $client->setAuthConfig(base_path() . '/client_secret.json');
    $client->addScope(\Google_Service_Calendar::CALENDAR);
    $client->setRedirectUri(URL::to('/') . '/v1/oauth2callback');
    $client->setAccessType('offline');
    $client->setPrompt('consent');
    $client->setIncludeGrantedScopes(true);

    $url = $client->createAuthUrl();
    print filter_var($url, FILTER_SANITIZE_URL);
Run Code Online (Sandbox Code Playgroud)

然后我手动转到 URL:

https://accounts.google.com/o/oauth2/auth?response_type=code&access_type=offline&client_id=123-blah&redirect_uri=http%3A%2F%2Flocalhost%3A7777%2Fv1%2Foauth2callback&state&scope=https%3A%2F%2Fwww.googleapis。 com%2Fauth%2Fcalendar&include_granted_scopes=true&prompt=同意

身份验证流程似乎一切正常,并将我返回到我尝试解码令牌的网址:

    $code = $request->code;
    $client = new Google\Client();
    $accessToken = $client->fetchAccessTokenWithAuthCode($code);
    var_dump($accessToken);
    exit;
Run Code Online (Sandbox Code Playgroud)

这给了我这个错误:

array(2) { ["error"]=> string(15) "invalid_request" ["error_description"]=> string(43) "无法根据请求确定客户端 ID。" }

google-api google-api-client google-oauth google-api-php-client

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

使用ruby google-api-client获取youtube视频数据

你好 !

我已经看到了很多类似的问题,但无法弄清楚为什么它们都没有给出明确的答案.

我正在尝试使用google-api-client gem连接到youtube数据api,以从youtube视频链接中检索缩略图.我假设我不需要处理(模糊我)oAuth身份验证.

  • 第一步:我使用google api控制台创建项目,授权Youtube Data API.在"API访问"选项卡中,我选择"创建客户端ID ...",并选择"服务帐户"选项.

它给了我一个客户ID,电子邮件地址和公钥指纹.

  • 第二:我使用google-api-client gem创建我的ruby脚本.我只是复制/粘贴文档中的示例:

    要求'google/api_client'

    client = Google :: APIClient.new

从我的客户端对象我以为我可以直接调用client.execute()来获取我的所有视频信息的原子提要.但我只是想知道如何做到这一点.

也许我还得获得oAuth授权?要获得令牌?

我错过了什么?

非常感谢您的贡献.

ruby youtube-api google-api-client

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

在Fragment中使用GoogleApiClient递归进入executePendingTransactions

我正在尝试在我的应用中使用Place Autocomplete API.我有一个主要的Activity.我有一个是Fragment其中的一部分MainActivity.在OnViewCreated()Fragment.

 private void rebuildGoogleApiClient() {
    // When we build the GoogleApiClient we specify where connected and connection failed
    // callbacks should be returned and which Google APIs our app uses.
    mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
            .enableAutoManage(activity, 0 /* clientId */, this)
            .addConnectionCallbacks(this)
            .addApi(Places.GEO_DATA_API)
            .build();
}
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

Caused by: java.lang.IllegalStateException: Recursive entry to executePendingTransactions
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1471)
        at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:488)
        at com.google.android.gms.common.api.zzl.zza(Unknown Source)
        at com.google.android.gms.common.api.GoogleApiClient$Builder.zzkL(Unknown Source)
        at com.google.android.gms.common.api.GoogleApiClient$Builder.build(Unknown Source)
        at com.app.projectpapri.Fragments.LocationScreen.rebuildGoogleApiClient(LocationScreen.java:69)
        at …
Run Code Online (Sandbox Code Playgroud)

android google-api-client android-fragments google-places-api

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