我们正在创建一个以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) 我正在尝试创建一组单元测试来测试 Bigquery 的 Google 客户端库。我正在努力制作一个 Unittest 文件,该文件将模拟客户端并让我测试我的输入。我提供了一个简单的脚本,它具有一些集合功能来返回属于数据集的表列表。
有人会向我展示一个模拟 Google 客户端库的示例示例作为我找到的文档@ https://github.com/googleapis/google-cloud-python/blob/master/bigquery/tests/unit/test_client.py是不直接与代码的方法交互,所以我无法将它应用到我的代码中。
感谢实现这一目标的任何想法或方法,我似乎无法在 Stack Overflow 上找到任何记录此问题的地方。
谢谢
from google.cloud import bigquery
def get_dataset():
client = bigquery.Client.from_service_account_json('some_client_secret.json')
dataset_id = 'some_project.some_dataset'
dataset = client.get_dataset(dataset_id)
full_dataset_id = "{}.{}".format(dataset.project, dataset.dataset_id)
friendly_name = dataset.friendly_name
print(
"Got dataset '{}' with friendly_name '{}'.".format(
full_dataset_id, friendly_name
)
)
# View dataset properties
print("Description: {}".format(dataset.description))
print("Labels:")
labels = dataset.labels
if labels:
for label, value in labels.items():
print("\t{}: {}".format(label, value))
else:
print("\tDataset has no labels defined.")
# View tables in …Run Code Online (Sandbox Code Playgroud) google-app-engine unit-testing mocking python-3.x google-client
我试图找出谷歌的GData API(之间的差异http://code.google.com/p/gdata-python-client/)和谷歌的API客户端库的Python(http://code.google.com/ p/google-api-python-client /).
他们似乎都是谷歌.哪个是官方的?他们有什么不同?第二个似乎主要使用OAuth.
如果有人有任何知识或使用经验,那么获得一些信息会很棒!
PS:我虽然把它放在超级用户身上,但因为它与编程有关,我认为这会更好.
python gdata-api gdata google-client google-api-python-client
我目前正在使用Google_Client api并想要获取用户名,电话,电子邮件和用户地址.
我设置了这些范围:
'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/user.birthday.read',
'https://www.googleapis.com/auth/user.addresses.read',
'https://www.googleapis.com/auth/user.emails.read',
'https://www.googleapis.com/auth/user.phonenumbers.read'
Run Code Online (Sandbox Code Playgroud)
当我点击google登录时,它会询问正确的权限,然后我会使用Google提供的代码获取访问令牌.
获取我请求的令牌people_service和配置文件数据后,如下所示:
$token = $this->client->fetchAccessTokenWithAuthCode($_GET['code']);
$people_service = new \Google_Service_PeopleService($this->client);
$profile = $people_service->people->get(
'people/me',
array('personFields' => 'addresses,birthdays,emailAddresses,phoneNumbers')
);
Run Code Online (Sandbox Code Playgroud)
它返回一个Google_Service_PeopleService_Person对象.
但是,当我尝试使用它时,就像getPhoneNumbers()它返回一个 Call to undefined method Google_Service_PeopleService_Person::getNames()错误.
有什么问题,我该怎么办?
Prereq:在https://code.google.com/apis/console/为urlshortener创建自己的API密钥
有很多文档可以通过js get api 将goo.gl网址转换为原始网址的各种方法,例如:这里,这里和这里 - 至少第一个甚至可以工作.
如果我稍微调整那个,使用insert api将url转换为一个小url,但是传递一个{ "longUrl": "https://codepen.io/" },但它会中断.如果你愿意,可以在http://codepen.io/johan/full/EHbGy#YOUR-API-KEY-HERE试试吧,或者在某处运行:
<script>
var api_key = 'YOUR-API-KEY-HERE';
function makeRequest() {
var request = gapi.client.urlshortener.url.insert({
'longUrl': 'https://codepen.io/'
});
request.execute(function(response) {
alert(JSON.stringify(window.got = response));
});
}
function load() {
gapi.client.setApiKey(api_key);
gapi.client.load('urlshortener', 'v1', makeRequest);
}
</script>
<script src="https://apis.google.com/js/client.js?onload=load"></script>
Run Code Online (Sandbox Code Playgroud)
......它只是回应错误:
{ "code": 400
, "message": "Required"
, "data":
[ { "domain": "global"
, "reason": "required"
, "message": "Required"
, "locationType": …Run Code Online (Sandbox Code Playgroud) 我面临的问题是Hint Request Number suggestion dialogue出现在屏幕上并以奇怪的动画迅速消失。
此对话在某些手机上运行良好,但在以下代码段中不适用于所有设备。
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.enableAutoManage(getActivity(), this)
.addApi(Auth.CREDENTIALS_API)
.build();
mGoogleApiClient.connect();
HintRequest hintRequest = new HintRequest.Builder()
.setHintPickerConfig(new CredentialPickerConfig.Builder()
.setShowCancelButton(true)
.build())
.setPhoneNumberIdentifierSupported(true)
.build();
PendingIntent intent =
Auth.CredentialsApi.getHintPickerIntent(mGoogleApiClient, hintRequest);
try {
startIntentSenderForResult(intent.getIntentSender(), RESOLVE_HINT, null, 0, 0, 0, new Bundle());
} catch (IntentSender.SendIntentException e) {
Log.e("Login", "Could not start hint picker Intent", e);
}
Run Code Online (Sandbox Code Playgroud) android credentials android-intent google-client google-oauth
我正在根据以下内容通过Google+进行身份验证:https: //developers.google.com/+/mobile/android/sign-in
大多数这个过程似乎很好.我遇到的问题是我们需要获得"一次性授权代码",以便我们的后端服务器可以代表用户在他们的许可下执行某些请求."为您的应用启用服务器端api访问"一节中对此进行了介绍.但是,由于多种原因,即使授权代码有效,我们的服务器也可能导致登录失败(例如,用户在我们的服务器上没有与Google +帐户相对应的帐户,在这种情况下,他们可以制作一).
如果发生这种情况,我们可能需要他们稍后再次登录.但我发现,当我使用google +执行第二次登录时,它会给我相同的授权码,即使它已被我们的服务器使用过.我已经尝试断开连接并重新连接到谷歌客户端API,并打电话GoogleApiClient.clearDefaultAccountAndReconnect(),但无论我做什么,我似乎最终得到相同的授权码.当然,当服务器尝试使用它时,它会被拒绝,因为它已被使用.
我想知道我在这里做错了什么.我有以下方法,在初始身份验证过程中调用,然后再次500从我们的服务器检测到响应状态(表示先前的调用失败,可能是因为代码已被使用):
private void dispatchGooglePlusAuthCodeAcquisition() {
AsyncTask<Void, Void, String> authAcquisition = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
Bundle authPreferences = new Bundle();
mUserPermissionNeededForAuthCode = false;
authPreferences.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES,
"");
String scopesString = Scopes.PROFILE;
WhenIWorkApplication app = (WhenIWorkApplication)WhenIWorkApplication.getInstance();
String serverClientID = app.getGoogleOAuthClientIDForPersonalServer();
String scope = "oauth2:server:client_id:" + serverClientID + ":api_scope:" + scopesString;
String code = null;
authPreferences.putBoolean(GoogleAuthUtil.KEY_SUPPRESS_PROGRESS_SCREEN, true);
try {
code = GoogleAuthUtil.getToken( …Run Code Online (Sandbox Code Playgroud) 我在多个页面上使用 Google API 时遇到问题。来自 Google 的示例工作正常,但所有代码都在一页上。
我有两页。第一页,用户点击登录按钮,第二页,我使用 google api 拉取用户信息。
第一页:
<?php
########## Google Settings.. Client ID, Client Secret from https://cloud.google.com/console #############
$google_client_id = 'myid';
$google_client_secret = 'mysecret';
$google_redirect_url = 'http://www.myWebsite.com/secondPage.php'; //path to your script
$google_developer_key = 'mydeveloperkey';
//include google api files
require_once '../includes/Google/autoload.php';
//start session
session_start();
$client = new Google_Client();
$client->setClientId($google_client_id);
$client->setClientSecret($google_client_secret);
$client->setRedirectUri($google_redirect_url);
$client->addScope("https://www.googleapis.com/auth/drive");
$client->addScope("https://www.googleapis.com/auth/calendar");
$client->addScope("https://www.googleapis.com/auth/gmail.compose");
$client->addScope("https://www.googleapis.com/auth/plus.me");
$drive_service = new Google_Service_Drive($client);
$calendar_service = new Google_Service_Calendar($client);
$gmail_service = new Google_Service_Gmail($client);
/************************************************
If we're logging out we just need …Run Code Online (Sandbox Code Playgroud) 我正在寻找使用Go后端服务器项目验证Android登录的ID令牌的方法.
在Go中使用Google API客户端库验证ID令牌的等效功能是什么?
从此页面上的" 使用Google API客户端库"部分
有Java和Python示例,并且有用于PHP,Node.js和其他语言的Google API客户端库的验证ID令牌链接.我检查了我的目标语言; 到这里
https://github.com/google/google-api-go-client/blob/master/GettingStarted.md
但是,我发现在Java和Python示例中没有用于验证令牌的等效函数.Go中是否有任何功能可以做这样的事情?
我不想使用令牌信息端点
https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=XYZ123
因为它引入了可能的延迟和网络错误.我希望使用Google API客户端库.请指导我在哪里研究.
我尝试使用 API 将文件从 Amazon S3 传输到 Google Cloud Storage。我在 GCP 控制台上成功了,但是当我使用服务帐户凭据编写 Python 脚本时,我得到了HttpError 403 when requesting https://storagetransfer.googleapis.com/v1/transferJobs?alt=json returned "The caller does not have permission
此外,我的服务帐户已经是存储对象管理员。
我正在使用的脚本
import google.auth
import google_auth_httplib2
import google.oauth2.service_account
from googleapiclient.discovery import build
_DEFAULT_SCOPES = ('https://www.googleapis.com/auth/cloud-platform',)
credentials = (
google.oauth2.service_account.Credentials.from_service_account_file(
key_path, scopes=_DEFAULT_SCOPES)
)
http = httplib2.Http()
http_authorized = google_auth_httplib2.AuthorizedHttp(
credentials, http=http)
conn = build('storagetransfer', 'v1', http=http_authorized, cache_discovery=False)
now = datetime.datetime.utcnow()
project_id='projectid'
transfer_spec = {
'awsS3DataSource': {
'bucketName': 's3_bucket',
'awsAccessKey': {
'accessKeyId': 'key',
'secretAccessKey': 'secret',
}
}, …Run Code Online (Sandbox Code Playgroud) python-3.x google-cloud-storage google-client google-cloud-platform
google-client ×10
android ×3
google-oauth ×2
php ×2
python-3.x ×2
credentials ×1
gdata ×1
gdata-api ×1
gmail-api ×1
go ×1
goo.gl ×1
google-api ×1
google-plus ×1
javascript ×1
mocking ×1
oauth ×1
python ×1
unit-testing ×1