我正在尝试在我们的网站上实施谷歌登录.我已经阅读了文档并在apis控制台上设置了一个应用程序.
我更喜欢注册对话框显示在弹出窗口中,并在用户登录后接受我将获得javascript回调的权限.这个api也支持根据文档.所以我在文档的帮助下构建了以下内容;-)
第一部分是使用正确的clientid和apikey加载google客户端脚本async和init脚本.
$gp = new googlePlus('@Trustpilot.Web.Social.Google.ClientID', '@Trustpilot.Web.Social.Google.ApiKey');
(function () {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client.js?onload=googlePlusClientLoad';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
Run Code Online (Sandbox Code Playgroud)
下一部分是使用谷歌客户端API的部分.加载client.js时调用handleClientLoad().该方法检查使用是否经过身份验证.如果用户是,我的想法是我想登录用户.如果用户尚未经过身份验证,则会有一个按钮,当单击handleAuthClick()时,它会调用handleClientLoad(),但会有一个弹出窗口,用户登录最多(使用谷歌帐户)并接受权限.登录后调用handleAuthResult()来登录用户.
function googlePlus(clientId, apiKey) {
this.clientId = clientId;
this.apiKey = apiKey;
this.scopes = 'https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email';
/// This method is called when the javascript is loaded async
this.handleClientLoad = function() {
gapi.client.setApiKey(this.apiKey);
window.setTimeout(this.authorize(true), 1);
};
this.handleAuthResult = function (authResult) {
console.log(authResult);
if (authResult && !authResult.error) {
var token = gapi.auth.getToken(); …Run Code Online (Sandbox Code Playgroud) javascript google-api google-authentication google-api-client
对于我自己的Gmail帐户,我有多个与之关联的电子邮件地址.例如,我的大学有一个与我的Gmail相关联的电子邮件地址,我可以从我的Gmail发送电子邮件,就像它们来自我的大学电子邮件地址一样.
我正在阅读Google API,我发现我可以获得用户的Gmail地址,但是我是否还可以获得与其Gmail帐户相关联的任何其他电子邮件地址?
当用户登录我的网站时,我想向他们提供与gmail相关的电子邮件地址列表,让他们选择他们想要使用的电子邮件地址.
编辑:谢谢大家的答案,但我不认为他们中的任何一个回答了这个问题.我一直在玩Google的OAuth游乐场.奇怪的是,我可以获得大量非常个人化的信息(用户联系人列表,甚至收到的电子邮件)但我无法获得用户的替代电子邮件地址.
我有一个kitkat api的问题,同时tringy获取谷歌帐户服务的访问令牌,在我的情况下谷歌音乐.因此,如果用户首先使用next方法尝试获取令牌:
public String getAuthToken(Account account)
throws AuthenticatorException, IOException {
String s1;
if (account == null) {
Log.e("MusicAuthInfo", "Given null account to MusicAuthInfo.getAuthToken()", new Throwable());
throw new AuthenticatorException("Given null account to MusicAuthInfo.getAuthToken()");
}
String s = getAuthTokenType(mContext);
try {
s1 = AccountManager.get(mContext).blockingGetAuthToken(account, s, true);
} catch (OperationCanceledException operationcanceledexception) {
throw new AuthenticatorException(operationcanceledexception);
}
if (s1 == null) {
throw new AuthenticatorException("Received null auth token.");
}
return s1;
}
Run Code Online (Sandbox Code Playgroud)
在这里,我得到s1 == null和系统推送通知:

当用户点击通知时,会出现下一个对话框:

当用户单击"确定"时,获取令牌的所有下一次迭代都会成功.
问题:如何绕过此确认或仅显示对话框,而不点击通知?
我正在使用Google API在Google云端硬盘上创建电子表格.
这一切都很好.
问题是共享文档的服务帐户的身份.这是一个生成的id.我希望它被标记为我的应用程序.
这可能吗? -

oauth google-api google-api-client google-oauth google-developers-console
我在我的Android应用程序中运行后台服务.我使用从登录活动中获取的IdToken在后端服务器上进行身份验证.该服务正在START_STICKY模式下运行,因此即使应用程序关闭,该服务仍会在后台运行以从后端服务器获取任何通知.我面临的问题是当IdToken过期时,我无法在服务中更新它.如果令牌已过期,则回调函数不会收到任何结果.如果令牌尚未过期,它会立即获得结果.
这是signIn函数和handleSignIn函数的代码.
private void signIn() {
new Thread(new Runnable() { public void run() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken("<My server_client_id>")
.build();
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(context)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn
(mGoogleApiClient);
if (opr.isDone()) {
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
// and the GoogleSignInResult will be available instantly.
Log.d(TAG, "Got cached sign-in");
GoogleSignInResult result = opr.get();
handleSignInResult(result);
} else {
// If the user has not …Run Code Online (Sandbox Code Playgroud) 我想要为了登录用户我必须使用这段代码:
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
Run Code Online (Sandbox Code Playgroud)
注销
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
disconnect();
}
});
Run Code Online (Sandbox Code Playgroud)
但是当用户重新启动应用程序并且他已经登录(之前没有退出)是否可以检测到这个"当前登录"状态?
显然,可以将"登录"保存在应用程序的设置(共享首选项)中,但是可以使用google api进行检测吗?
android google-api-client android-googleapiclient google-signin googlesigninapi
我无法理解为什么这个非常简单的活动会产生内存泄漏.
它遵循此处给出的指导原则:https://developer.android.com/training/location/receive-location-updates.html以及此处给出的示例代码:https://github.com/googlesamples/android-play-location /树/主/ LocationUpdates
我还注意到,如果我不重写LocationCallback类的onLocationResult方法,则会解决内存泄漏问题.但就这种方式而言,LocationCallback完全没用.
谢谢您的帮助!
public class TestLeaks extends Activity {
private FusedLocationProviderClient mFusedLocationClient; // Access to Fused Loc. Provider API
private LocationRequest mLocationRequest; // Stores parameters for requests to F.L.P.Api
private LocationCallback mLocationCallback; // Callback for Location events
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_leaks);
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
Location loc = locationResult.getLastLocation();
((TextView) findViewById(R.id.latitude)).setText(String.format(Locale.US, "%.6f", loc.getLatitude()));
((TextView) findViewById(R.id.longitude)).setText(String.format(Locale.US, …Run Code Online (Sandbox Code Playgroud) android memory-leaks google-api-client location-updates fusedlocationproviderclient
像往常一样,我的代码中有很多代码,我LoginActivity真的更愿意将Activity责任与Google Play注册分开.
在LoginActivity多次重写此代码之后,在许多不同的应用程序中,简单(而不是那么优雅)的解决方案是将Google API客户端创建为Application类对象.但是,由于连接状态会影响用户体验流程,因此我从未对这种方法感到高兴.
有一种优雅的方式放置在GoogleApiClient外面Activity吗?
android design-patterns google-api-client google-plus google-play-services
我正在创建一个 Google Doc to HTML 转换器,我想使用Doc Api而不是使用 Drive Api 将其导出为 HTML:
$service = new Google_Service_Docs($client);
$request = $service->documents->get($docId);
$elements = $request->getBody()->getContent();
Run Code Online (Sandbox Code Playgroud)
$elements 是 Google_Service_Docs_StructuralElement 的数组
循环遍历段落 > 元素,如果有内联对象,则使用 Google_Service_Docs_InlineObjectElement 设置 inlineObjectElement 属性
问题是:如何获取 Google_Service_Docs_InlineObjectElement 的内容以将其保存为文件?我们在这个对象中只有一个 inlineObjectId ......
google-api google-docs-api google-api-client google-api-php-client
如何使用 cURL 从刷新令牌中获取新的访问令牌?
在 PHP 中,我会做这样的事情:
$client = new Google_Client();
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
$client->refreshToken($refresh_token);
$access_token = $client->getAccessToken();
Run Code Online (Sandbox Code Playgroud)
如何使用 cURL 完成同样的事情?
我无法从他们的文档中找到它。
curl google-api google-analytics-api google-api-client google-oauth
android ×5
google-api ×5
google-oauth ×2
curl ×1
email ×1
fusedlocationproviderclient ×1
gmail ×1
google-plus ×1
javascript ×1
memory-leaks ×1
oauth ×1