我正在尝试将Google +登录集成到Android应用程序中。 API正在连接,登录也有效。但遗憾的是,我无法检索用户个人资料信息。我在开发者控制台上放了2个SHA1键。一个是使用Android的SDK的debug.keystore文件,另一个是来自Android Studio中生成的项目密钥库文件。
GoogleApiClient的设置如下:
mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API, Plus.PlusOptions.builder().build()).addScope(Plus.SCOPE_PLUS_PROFILE)
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
onConnection方法:
@Override
public void onConnected(Bundle arg0) {
signedInUser = false;
//Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this);
Toast.makeText(this, "Connected", Toast.LENGTH_LONG).show();
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
String personName = currentPerson.getDisplayName();
String personPhotoUrl = currentPerson.getImage().getUrl();
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
username.setText(personName);
emailLabel.setText(email);
}
}
AndroidManifest.xml权限:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
build.gradle(app):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
..........
..........
dependencies {
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-plus:8.1.0'
compile files('libs/android_adcolony_2.2.0.jar')
compile files('libs/adcolony.jar')
compile files('libs/heyzap-ads-sdk.jar')
compile files('libs/android_unityads_4.0.1.jar')
}
我按照官方google + api文档提供了有关使用keytool设置配置文件和生成SHA1哈希密钥的信息。
logcat的:
10-19 13:06:36.961 25859-25859/com.littlefroginc.rollnearn.android.activities E/Zygote﹕ MountEmulatedStorage()
10-19 13:06:36.971 5859-25859/com.littlefroginc.rollnearn.android.activities E/Zygote﹕ v2
10-19 13:06:36.971 25859-25859/com.littlefroginc.rollnearn.android.activities I/libpersona﹕ KNOX_SDCARD checking this for 10272
10-19 13:06:36.971 25859-25859/com.littlefroginc.rollnearn.android.activities I/SELinux﹕ Function: selinux_compare_spd_ram, SPD-policy is existed. and_ver=SEPF_SM-G920I_5.0.2 ver=22
10-19 13:06:36.971 25859-25859/com.littlefroginc.rollnearn.android.activities I/libpersona﹕ KNOX_SDCARD not a persona
10-19 13:06:36.971 25859-25859/com.littlefroginc.rollnearn.android.activities I/SELinux﹕ Function: selinux_compare_spd_ram , priority [2] , priority version is VE=SEPF_SM-G920I_5.1.1_0035
10-19 13:06:36.971 25859-25859/com.littlefroginc.rollnearn.android.activities E/Zygote﹕ accessInfo : 0
10-19 13:06:36.971 25859-25859/com.littlefroginc.rollnearn.android.activities E/SELinux﹕ [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
10-19 13:06:37.021 25859-25859/com.littlefroginc.rollnearn.android.activities D/TimaKeyStoreProvider﹕ TimaSignature is unavailable
10-19 13:06:37.021 25859-25859/com.littlefroginc.rollnearn.android.activities D/ActivityThread﹕ Added TimaKeyStore provider
10-19 13:06:37.091 25859-25859/com.littlefroginc.rollnearn.android.activities I/InjectionManager﹕ Inside getClassLibPath + mLibMap{0=, 1=}
10-19 13:06:37.111 25859-25859/com.littlefroginc.rollnearn.android.activities I/InjectionManager﹕ Inside getClassLibPath caller
10-19 13:06:37.151 25859-25880/com.littlefroginc.rollnearn.android.activities I/GMPM﹕ App measurement is starting up
10-19 13:06:37.151 25859-25859/com.littlefroginc.rollnearn.android.activities D/InjectionManager﹕ InjectionManager
10-19 13:06:37.151 25859-25859/com.littlefroginc.rollnearn.android.activities D/InjectionManager﹕ fillFeatureStoreMap com.littlefroginc.rollnearn.android.activities
10-19 13:06:37.151 25859-25859/com.littlefroginc.rollnearn.android.activities I/InjectionManager﹕ Constructor com.littlefroginc.rollnearn.android.activities, Feature store :{}
10-19 13:06:37.151 25859-25859/com.littlefroginc.rollnearn.android.activities I/InjectionManager﹕ featureStore :{}
10-19 13:06:37.161 25859-25880/com.littlefroginc.rollnearn.android.activities E/GMPM﹕ getGoogleAppId failed with status: 10
10-19 13:06:37.161 25859-25880/com.littlefroginc.rollnearn.android.activities E/GMPM﹕ Uploading is not possible. App measurement disabled
10-19 13:06:37.161 25859-25859/com.littlefroginc.rollnearn.android.activities D/SecWifiDisplayUtil﹕ Metadata value : SecSettings2
10-19 13:06:37.181 25859-25859/com.littlefroginc.rollnearn.android.activities D/PhoneWindow﹕ *FMB* installDecor mIsFloating : false
10-19 13:06:37.181 25859-25859/com.littlefroginc.rollnearn.android.activities D/PhoneWindow﹕ *FMB* installDecor flags : -2139029248
10-19 13:06:37.201 25859-25859/com.littlefroginc.rollnearn.android.activities I/InjectionManager﹕ Inside getClassLibPath caller
10-19 13:06:37.201 25859-25859/com.littlefroginc.rollnearn.android.activities W/ResourcesManager﹕ Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
10-19 13:06:37.201 25859-25859/com.littlefroginc.rollnearn.android.activities W/ResourcesManager﹕ Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
10-19 13:06:37.271 25859-25859/com.littlefroginc.rollnearn.android.activities D/Activity﹕ performCreate Call Injection manager
10-19 13:06:37.271 25859-25859/com.littlefroginc.rollnearn.android.activities I/InjectionManager﹕ dispatchOnViewCreated > Target : com.littlefroginc.rollnearn.android.activities.TestActivity isFragment :false
10-19 13:06:37.281 25859-25889/com.littlefroginc.rollnearn.android.activities D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
10-19 13:06:37.291 25859-25859/com.littlefroginc.rollnearn.android.activities D/PhoneWindow﹕ *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
10-19 13:06:37.291 25859-25859/com.littlefroginc.rollnearn.android.activities D/PhoneWindow﹕ *FMB* isFloatingMenuEnabled return false
10-19 13:06:37.321 25859-25859/com.littlefroginc.rollnearn.android.activities D/SRIB_DCS﹕ log_dcs ThreadedRenderer::initialize entered!
10-19 13:06:37.341 25859-25889/com.littlefroginc.rollnearn.android.activities D/libEGL﹕ loaded /vendor/lib64/egl/libGLES_mali.so
10-19 13:06:37.361 25859-25889/com.littlefroginc.rollnearn.android.activities I/OpenGLRenderer﹕ Initialized EGL, version 1.4
10-19 13:06:37.371 25859-25889/com.littlefroginc.rollnearn.android.activities I/OpenGLRenderer﹕ HWUI protection enabled for context , &this =0x7f761bfec0 ,&mEglDisplay = 1 , &mEglConfig = 1982403248
10-19 13:06:37.371 25859-25889/com.littlefroginc.rollnearn.android.activities D/OpenGLRenderer﹕ Get maximum texture size. GL_MAX_TEXTURE_SIZE is 8192
10-19 13:06:37.371 25859-25889/com.littlefroginc.rollnearn.android.activities D/OpenGLRenderer﹕ Enabling debug mode 0
10-19 13:06:37.371 25859-25889/com.littlefroginc.rollnearn.android.activities D/mali_winsys﹕ new_window_surface returns 0x3000, [1440x2560]-format:1
10-19 13:06:37.471 25859-25859/com.littlefroginc.rollnearn.android.activities I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@324ea6d time:3900228
10-19 13:06:38.441 25859-25859/com.littlefroginc.rollnearn.android.activities D/SRIB_DCS﹕ log_dcs ThreadedRenderer::initialize entered!
10-19 13:06:38.441 25859-25889/com.littlefroginc.rollnearn.android.activities D/mali_winsys﹕ new_window_surface returns 0x3000, [497x181]-format:1
答案 0 :(得分:1)
尝试设置您的GoogleApiClient:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(new Scope(Scopes.PROFILE))
.addScope(new Scope(Scopes.EMAIL))
.build();
如果您的清单中没有以下代码,请将其添加到应用程序标记
旁边<application>
.
.
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
.
.
</application>
答案 1 :(得分:0)
您可以使用此代码为我工作
mGoogleApiClient = new GoogleApiClient.Builder(LoginActivity.this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
ang收到电子邮件
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);