I have only copied setUp function from " get ready to use the api " People API and I followed the steps listed it. I've added my clientid and my secretid but i have always the same error. i try to get information about profil user (specifically gender and age) from google plus account to classify users.
Google authentification linked to Firebase works perfectly and gives me name, mail and Photourl. but when i try to connect to google plus using OAuth 2.0 - Google ,It's not working
--> I don't understand why CODE is always null
String redirectUrl = "urn:ietf:wg:oauth:2.0:oob";
String scope = "https://www.googleapis.com/auth/contacts.readonly";
// Step 1: Authorize -->
String authorizationUrl =
new GoogleBrowserClientRequestUrl(clientId, redirectUrl,
Arrays.asList(scope)).build();
// Point or redirect your user to the authorizationUrl.
System.out.println("Go to the following link in your browser:");
System.out.println(authorizationUrl);
// Read the authorization code from the standard input stream.
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("What is the authorization code?");
String code = in.readLine();
Manifest File :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
Build.grale :
configurations {
all {
exclude module: 'httpclient'
}
}
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v13:27.1.0'
implementation 'com.google.firebase:firebase-storage:12.0.1'
compile 'com.google.apis:google-api-services-people:v1-rev229-1.23.0'
compile 'com.google.api-client:google-api-client-android:1.22.0'
implementation 'com.google.firebase:firebase-auth:12.0.1'
compile 'com.google.android.gms:play-services-location:12.0.1'
compile 'com.google.android.gms:play-services-auth:12.0.1'
compile 'com.google.android.gms:play-services-plus:12.0.1'
compile 'com.google.api-client:google-api-client:1.23.0'
//noinspection GradleCompatible
implementation 'com.google.firebase:firebase-database:12.0.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
Logcat :
java.lang.RuntimeException: Unable to start activity ComponentInfo{ .SecondActivity20paste}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.NullPointerException
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:213)
at com.google.api.client.util.Preconditions.checkNotNull(Preconditions.java:127)
at com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.setCode(AuthorizationCodeTokenRequest.java:147)
at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.setCode(GoogleAuthorizationCodeTokenRequest.java:147)
at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.setCode(GoogleAuthorizationCodeTokenRequest.java:79)
at com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest.<init>(AuthorizationCodeTokenRequest.java:103)
at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.<init>(GoogleAuthorizationCodeTokenRequest.java:111)
at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.<init>(GoogleAuthorizationCodeTokenRequest.java:92)
at com.teeen.user.teeen.SecondActivity20paste.setUp(SecondActivity20paste.java:561)
at com.teeen.user.teeen.SecondActivity20paste.onCreate(SecondActivity20paste.java:176)
at android.app.Activity.performCreate(Activity.java:6955)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
04-04 10:24:25.336 25756-25785/com. W/MessengerIpcClient: Timing out request: 1
04-04 10:24:25.338 25756-25784/com. E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
04-04 10:25:25.375 25756-25784/com. E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
Please help me how to resolve.