android – 在我的应用程序中启用Gmail登录
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android – 在我的应用程序中启用Gmail登录,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3903字,纯文字阅读大概需要6分钟。
内容图文
![android – 在我的应用程序中启用Gmail登录](/upload/InfoBanner/zyjiaocheng/703/ee0fc2235d2e4c0c9cfd2e622911eb88.jpg)
这些是我登录我的应用程序所需的最少细节:
guid(Global Unique ID)
fname
lname
gender
对于Facebook登录很明显,可以这样做:
JSONObject json = Util.parseJson(facebook.request("me");
获取上面指定的所有数据.
有,我有办法用Gmail做类似和简单的事情吗?
我读了this,其中说:
No, there is no such SDK(like facebook) and if you want to access the
emails of Gmail then you need to implement your own email client and
for that follow the above link shared by Spk.
但我只想要很少的用户细节,我不需要任何与他的邮件相关的东西……,这些都属于授权(如果我是对的).我只需要身份验证:
我也阅读了this,但看起来不会有任何帮助.
这是我现在的代码:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
import com.google.android.gms.plus.GooglePlusUtil;
import com.google.android.gms.plus.PlusClient;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements ConnectionCallbacks,
OnConnectionFailedListener {
private static final int REQUEST_CODE_RESOLVE_ERR = 7;
private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
private String TAG = "GmailLogin";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int errorCode = GooglePlusUtil.checkGooglePlusApp(this);
if (errorCode != GooglePlusUtil.SUCCESS) {
GooglePlusUtil.getErrorDialog(errorCode, this, 0).show();
} else {
mPlusClient = new PlusClient.Builder(this, this, this)
.setVisibleActivities( "http://schemas.google.com/AddActivity",
"http://schemas.google.com/BuyActivity").build();
mConnectionProgressDialog = new ProgressDialog(this);
mConnectionProgressDialog.setMessage("Signing in...");
Button signInButton = (Button) findViewById(R.id.sign_in_button);
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mConnectionResult == null) {
mConnectionProgressDialog.show();
} else {
try {
mConnectionResult
.startResolutionForResult(
MainActivity.this,
REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
// Try connecting again.
mConnectionResult = null;
mPlusClient.connect();
}
}
}
});
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (result.hasResolution()) {
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
// Save the result and resolve the connection failure upon a user click.
mConnectionResult = result;
}
@Override
protected void onActivityResult(int requestCode, int responseCode,
Intent intent) {
if (requestCode == REQUEST_CODE_RESOLVE_ERR
&& responseCode == RESULT_OK) {
mConnectionResult = null;
mPlusClient.connect();
}
}
@Override
public void onConnected() {
String accountName = mPlusClient.getAccountName();
Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG)
.show();
}
@Override
public void onDisconnected() {
Log.d(TAG, "disconnected");
}
@Override
protected void onStart() {
super.onStart();
mPlusClient.connect();
}
@Override
protected void onStop() {
super.onStop();
mPlusClient.disconnect();
}
}
非常感谢任何帮助,谢谢.
解决方法:
您不应使用Gmail通过Google帐户进行用户身份验证.您可以使用Google登录Android.这将允许您在使用OAuth获取所需权限后访问用户的配置文件信息.在这里查看指南:
https://developers.google.com/+/mobile/android/sign-in
内容总结
以上是互联网集市为您收集整理的android – 在我的应用程序中启用Gmail登录全部内容,希望文章能够帮你解决android – 在我的应用程序中启用Gmail登录所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。