public void init (final int instanceID) { script_id = instanceID; GUtils.setScriptInstance(script_id); if (GUtils.checkGooglePlayService(activity)) { Log.d(TAG, "Play Service Available."); } GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN) .requestScopes(new Scope(Scopes.GAMES)) .requestEmail() .build(); mGoogleSignInClient = GoogleSignIn.getClient(activity, gso); Log.d(TAG, "Google::Initialized"); onStart(); }
public LoginGoogle(final Context context, SignInButton button, final Activity act, PreferencesShared pref) { this.context = context; preferencesShared = pref; GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken("473547758853-nm840bumsu5km04gbgtdee1fhtod1ji6.apps.googleusercontent.com").build(); gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.PLUS_LOGIN)).requestScopes(new Scope(Scopes.PLUS_ME)).requestEmail().requestIdToken("473547758853-nm840bumsu5km04gbgtdee1fhtod1ji6.apps.googleusercontent.com").build(); mGoogleApiClient = new GoogleApiClient.Builder(context.getApplicationContext()) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); button.setSize(SignInButton.SIZE_STANDARD); button.setScopes(gso.getScopeArray()); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); act.startActivityForResult(signInIntent, 101); } }); }
private void loginGoogleAPI() { if (!(context instanceof FragmentActivity)) { return; } gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .requestProfile() .requestId() .requestScopes(new Scope(Scopes.PLUS_LOGIN), new Scope(Scopes.DRIVE_FILE)) .requestServerAuthCode(CLIENT_ID) .build(); if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(context) .addApi(com.google.android.gms.auth.api.Auth.GOOGLE_SIGN_IN_API, gso) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } if (!mGoogleApiClient.isConnected()) { mGoogleApiClient.connect(); } else { sendAuthRequest(); } }
public void createConnection(AppCompatActivity mActivity) { this.activity = mActivity; userData = new UserLoginDetails(); if (Utility.checkPlayServices(mActivity)) { GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.PROFILE)) .requestScopes(new Scope(Scopes.PLUS_LOGIN)) .requestProfile() .requestEmail() .build(); if (mGoogleApiClient == null) { // [START create_google_api_client] // Build GoogleApiClient with access to basic profile mGoogleApiClient = new GoogleApiClient.Builder(mActivity) .enableAutoManage(mActivity,this) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) //.addApi(Plus.API) .build(); } } }
@Test public void testLoginGoogleSuccess() throws Exception { InOrder inOrder = inOrder(mMockGoogleApiClient); mRxLogin.mGoogleApiClient = mMockGoogleApiClient; mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN)) .subscribe(mGoogleSubscriber); // wait for connection Thread.sleep(20); mRxLogin.mGoogleCallback.onSuccess(mGoogleSignInResult); mGoogleSubscriber.awaitTerminalEvent(); verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712)); inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS)); inOrder.verify(mMockGoogleApiClient).disconnect(); mGoogleSubscriber.assertNoErrors(); mGoogleSubscriber.assertValueCount(1); mGoogleSubscriber.assertTerminated(); assertThat(mRxLogin.mGoogleApiClient).isNull(); assertThat(mRxLogin.mGoogleCallback).isNull(); }
@Test public void testLoginGoogleCancel() throws Exception { InOrder inOrder = inOrder(mMockGoogleApiClient); mRxLogin.mGoogleApiClient = mMockGoogleApiClient; mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN)) .subscribe(mGoogleSubscriber); // wait for connection Thread.sleep(20); mRxLogin.mGoogleCallback.onCancel(); mGoogleSubscriber.awaitTerminalEvent(); verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712)); inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS)); inOrder.verify(mMockGoogleApiClient).disconnect(); mGoogleSubscriber.assertError(LoginException.class); mGoogleSubscriber.assertTerminated(); assertThat(mRxLogin.mGoogleApiClient).isNull(); assertThat(mRxLogin.mGoogleCallback).isNull(); }
@Test public void testLoginGoogleError() throws Exception { InOrder inOrder = inOrder(mMockGoogleApiClient); mRxLogin.mGoogleApiClient = mMockGoogleApiClient; mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN)) .subscribe(mGoogleSubscriber); // wait for connection Thread.sleep(20); mRxLogin.mGoogleCallback.onError(mGoogleSignInResult); mGoogleSubscriber.awaitTerminalEvent(); verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712)); inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS)); inOrder.verify(mMockGoogleApiClient).disconnect(); mGoogleSubscriber.assertError(LoginException.class); mGoogleSubscriber.assertTerminated(); assertThat(mRxLogin.mGoogleApiClient).isNull(); assertThat(mRxLogin.mGoogleCallback).isNull(); }
@Test public void testLoginGoogleConnectionError() throws Exception { when(mMockGoogleApiClient.blockingConnect(eq(10L), eq(TimeUnit.SECONDS))) .thenReturn(new ConnectionResult(ConnectionResult.API_UNAVAILABLE)); InOrder inOrder = inOrder(mMockGoogleApiClient); mRxLogin.mGoogleApiClient = mMockGoogleApiClient; mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN)) .subscribe(mGoogleSubscriber); mGoogleSubscriber.awaitTerminalEvent(); verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712)); inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS)); inOrder.verify(mMockGoogleApiClient).disconnect(); mGoogleSubscriber.assertError(LoginException.class); mGoogleSubscriber.assertTerminated(); assertThat(mRxLogin.mGoogleApiClient).isNull(); assertThat(mRxLogin.mGoogleCallback).isNull(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.historydata_layout); mClient = new GoogleApiClient.Builder(this) .addApi(Fitness.HISTORY_API) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ)) .addScope(new Scope(Scopes.FITNESS_BODY_READ)) .addScope(new Scope(Scopes.FITNESS_LOCATION_READ)) .addScope(new Scope(Scopes.FITNESS_NUTRITION_READ)) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); mAggregateCheckBox = (CheckBox)findViewById(R.id.aggregatecheckbox); mStartDateText = (TextView)findViewById(R.id.startdate); mEndDateText = (TextView)findViewById(R.id.enddate); mResultsText = (TextView)findViewById(R.id.results); setUpSpinnerDropDown(); setUpListView(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.subscriptiondata_layout); mClient = new GoogleApiClient.Builder(this) .addApi(Fitness.RECORDING_API) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ)) .addScope(new Scope(Scopes.FITNESS_BODY_READ)) .addScope(new Scope(Scopes.FITNESS_LOCATION_READ)) .addScope(new Scope(Scopes.FITNESS_NUTRITION_READ)) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); setUpSpinnerDropDown(); setUpListView(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sensordata_layout); mLiveDataText = (TextView)findViewById(R.id.livedata); setUpSpinnerDropDown(); setUpListView(); mClient = new GoogleApiClient.Builder(this) .addApi(Fitness.SENSORS_API) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ)) .addScope(new Scope(Scopes.FITNESS_BODY_READ)) .addScope(new Scope(Scopes.FITNESS_LOCATION_READ)) .addScope(new Scope(Scopes.FITNESS_NUTRITION_READ)) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); }
@Override public void onCreate() { super.onCreate(); googleApiClient = new GoogleApiClient.Builder(this) .addApi(Plus.API) .addApi(Fitness.SENSORS_API) .addApi(Fitness.SESSIONS_API) .addApi(Fitness.HISTORY_API) .addApi(Fitness.RECORDING_API) .addApi(LocationServices.API) .addScope(new Scope(Scopes.PROFILE)) .addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE)) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)) .addConnectionCallbacks(connectionListenerAdapter) .addOnConnectionFailedListener(connectionListenerAdapter) .build(); }
@Override public void rxAction(int requestCode) { Assert.assertEquals(requestCode, ActivityResponses.GET_LOGINTOKEN); final Activity activity = (Activity) getContext(); final String[] permissions = new String[]{Manifest.permission.GET_ACCOUNTS}; final Scope[] scopes = {new Scope(Scopes.PROFILE), new Scope(Scopes.EMAIL)}; // NB : Rationale is optional and can be null final SnackbarRationaleOperator rationaleOperator = new SnackbarRationaleOperator(this, "Need permission for ..."); getLoginToken(activity, permissions, scopes, rationaleOperator) .subscribe(new Consumer<String>() { @Override public void accept(String s) { Toast.makeText(getContext(), "Token is : " + s, Toast.LENGTH_SHORT).show(); } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) { Toast.makeText(getContext(), "Exception : " + throwable, Toast.LENGTH_SHORT).show(); } }); }
/** * Build a {@link GoogleApiClient} that will authenticate the user and allow the application * to connect to Fitness APIs. The scopes included should match the scopes your app needs * (see documentation for details). Authentication will occasionally fail intentionally, * and in those cases, there will be a known resolution, which the OnConnectionFailedListener() * can address. Examples of this include the user never having signed in before, or * having multiple accounts on the device and needing to specify which account to use, etc. */ private void buildFitnessClient(final Context context) { if (context != null) { Log.i(TAG, "Creating the Google API Client with context: " + context.getClass().getName()); // Create the Google API Client mClient = new GoogleApiClient.Builder(context) .addApiIfAvailable(Plus.API) .addApiIfAvailable(Fitness.SENSORS_API) .addApi(Fitness.SESSIONS_API) .addApi(Fitness.HISTORY_API) .addApi(Fitness.RECORDING_API) //.addApi(LocationServices.API) .addScope(new Scope(Scopes.PROFILE)) //.addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE)) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } }
@Override public void login(Activity activity) { mActivity = activity; mRequestMap = new HashMap<>(); mSettingsManager = new SettingsManager(activity); mGoogleApiClient = new GoogleApiClient.Builder(mActivity) .addApi(Fitness.HISTORY_API) .addScope(new Scope(Scopes.FITNESS_LOCATION_READ)) .addScope(new Scope(Scopes.FITNESS_NUTRITION_READ)) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ)) .addScope(new Scope(Scopes.FITNESS_BODY_READ)) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); if(mGoogleApiClient != null) { mGoogleApiClient.connect(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); setContentView(R.layout.select_domain); TextView server = (TextView) findViewById(R.id.textView_server_url); url = getIntent().getStringExtra("server"); server.setText(url); callbackManager = CallbackManager.Factory.create(); findViewById(R.id.button_domain_google).setOnClickListener(this); ((SignInButton) findViewById(R.id.button_domain_google)).setSize(SignInButton.SIZE_WIDE); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(new Scope(Scopes.PROFILE)) .addScope(new Scope(Scopes.EMAIL)) .build(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getActivity()); loginManager = LoginManager.getInstance(); callbackManager = CallbackManager.Factory.create(); mActivity = getActivity(); mContext = getActivity().getApplicationContext(); //Google mGoogleApiClient = new GoogleApiClient.Builder(mContext) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(new Scope(Scopes.PROFILE)) .build(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); plusClient = new PlusClient.Builder(this, this, this); plusClient.setScopes(Scopes.PLUS_LOGIN); plusClient.setVisibleActivities( "http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity"); client = plusClient.build(); findViewById(R.id.button_sign_in).setOnClickListener(this); dialog = new ProgressDialog(this); getIntent().getAction(); }
@Override public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); getSherlockActivity().getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); mPlusClient = new PlusClient.Builder(this.getActivity().getApplicationContext(), this, this) .setActions("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity") .setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_PROFILE).build(); mConnectionProgressDialog = new ProgressDialog(this.getActivity()); mConnectionProgressDialog.setTitle("Login"); // mConnectionProgressDialog.setCancelable(false); mConnectionProgressDialog.setMessage(getSherlockActivity().getString(R.string.google_login_)); }
private void initializeGoogleSignIn() { GoogleSignInOptions signInOptions = new GoogleSignInOptions .Builder() .requestId() .requestEmail() .requestProfile() .build(); mApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this, this) .addApi(Auth.GOOGLE_SIGN_IN_API, signInOptions) .build(); SignInButton googleSignInButton = (SignInButton) findViewById(R.id.google_sign_in); //signInButton.setColorScheme(SignInButton.COLOR_DARK); googleSignInButton.setSize(SignInButton.SIZE_WIDE); googleSignInButton.setScopes(new Scope[]{new Scope(Scopes.PLUS_LOGIN)}); for (int i = 0; i < googleSignInButton.getChildCount(); i++) if (googleSignInButton.getChildAt(i) instanceof TextView) { TextView textView = (TextView) googleSignInButton.getChildAt(i); textView.setTextSize(15); textView.setText(R.string.sign_in_with_google); textView.setPadding(0, 0, 20, 0); break; } googleSignInButton.setOnClickListener(this); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); createLoadersWithValidContext(); //noinspection ConstantConditions final String clientId = getContext().getString(R.string.gdrive_client_id); GoogleSignInOptions gso = new Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .requestServerAuthCode(clientId, true) .requestScopes(new Scope(Scopes.DRIVE_FILE)) .build(); AuthenticationInfo auth = Preferences.getAuthenticationInfo(getContext(), Provider.GDRIVE); if (auth == null || TextUtils.isEmpty(auth.serverAuthCode)) { // Request the user to login into its Google account and request permissions mGoogleApiClient = new GoogleApiClient.Builder(getContext()) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(@Nullable Bundle bundle) { Auth.GoogleSignInApi.signOut(mGoogleApiClient); Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); startActivityForResult(signInIntent, REQUEST_CODE_OAUTH); } @Override public void onConnectionSuspended(int cause) { } }) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); mGoogleApiClient.connect(); return; } // Has a valid server token. Just retrieve an accessToken requestAccessToken(); }
/** * Called to have the fragment instantiate its user interface view. This is optional, * and non-graphical fragments can return null (which is the default implementation). * This will be called between onCreate(Bundle) and onActivityCreated(Bundle). * If you return a View from here, you will later be called in onDestroyView when the * view is being released. * * @param inflater The LayoutInflater object that can be used to inflate any views in the fragment, * @param container If non-null, this is the parent view that the fragment's UI should be attached to. * The fragment should not add the view itself, but this can be used to generate the LayoutParams of the view. * @param savedInstanceState If non-null, this fragment is being re-constructed from a previous saved state as given here. * * @return View for fragment's UI, or null * */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_login, container, false); setHeader(); // request user id, email address, and basic profile GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.PLUS_LOGIN)) .requestServerAuthCode(getString(R.string.OAuth_client_ID, false)) .build(); // create GoogleApiClient object mGoogleApiClient = new GoogleApiClient.Builder(getContext()) .enableAutoManage(getActivity() /* Fragment Activity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); // register google sign-in button mSignInButton = (SignInButton) view.findViewById(R.id.loginButton); mSignInButton.setSize(SignInButton.SIZE_WIDE); mSignInButton.setScopes(gso.getScopeArray()); // register UI elements mMainLogo = (ImageView) view.findViewById(R.id.mainLogo); mProfileImage = (CircleImageView) view.findViewById(R.id.profilePicture); mWelcomeText = (TextView) view.findViewById(R.id.welcomeText); mContinueButton = (Button) view.findViewById(R.id.continue_button); // register OnClickListener view.findViewById(R.id.loginButton).setOnClickListener(this); return view; }
public GoogleApiClient getGoogleSignInClient() { if (googleSignInClient == null) { googleSignInClient = new GoogleApiClient.Builder(this).addApi(GOOGLE_SIGN_IN_API, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail() .requestScopes(new Scope("https://www.googleapis.com/auth/contacts.readonly")) .requestScopes(new Scope(Scopes.PROFILE)) .requestServerAuthCode(BuildConfig.GMS_SERVER_ID) .build()) .build(); } return googleSignInClient; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); signInButton = (SignInButton) findViewById(R.id.main_googlesigninbtn); signInButton.setOnClickListener(this); frameLogin = (LinearLayout) findViewById(R.id.frame_login); toolbar = (Toolbar) findViewById(R.id.main_toolbar); recyclerView = (RecyclerView) findViewById(R.id.main_recycler); progressBar = (ProgressBar) findViewById(R.id.main_progress); GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) // The serverClientId is an OAuth 2.0 web client ID .requestServerAuthCode(getString(R.string.clientID)) .requestEmail() .requestScopes(new Scope(Scopes.PLUS_LOGIN), new Scope(PeopleScopes.CONTACTS_READONLY), new Scope(PeopleScopes.USER_EMAILS_READ), new Scope(PeopleScopes.USERINFO_EMAIL), new Scope(PeopleScopes.USER_PHONENUMBERS_READ)) .build(); // To connect with Google Play Services and Sign In mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this, this) .addOnConnectionFailedListener(this) .addConnectionCallbacks(this) .addApi(Auth.GOOGLE_SIGN_IN_API, signInOptions) .build(); }
private void configureGoogleClient() { mGso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.PLUS_LOGIN)) .requestEmail() .build(); mGoogleApiClient = new GoogleApiClient.Builder(mContext) .enableAutoManage((LoginActivity) mContext, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, mGso) .build(); mView.setGoogleButtonScope(mGso); }
public GoogleApiClient buildApiClient(){ return new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API, Plus.PlusOptions.builder().build()) .addScope(new Scope(Scopes.PROFILE)) .build(); }
public void onCreate(FragmentActivity fragmentActivity, @Nullable Class<?> newActivity) { this.currentActivity = fragmentActivity; this.newActivity = newActivity; //Configure sign-in to request the user's ID, email address, and basic profile. gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.DRIVE_APPFOLDER)) .requestEmail() .build(); mGoogleApiClient = new GoogleApiClient.Builder(currentActivity) .enableAutoManage(currentActivity, this) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Initialize the PlusClient connection. // Scopes indicate the information about the user your application will be able to access. mPlusClient = new PlusClient.Builder(this, this, this).setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_PROFILE).build(); }
public void buildFitnessClient(final Context context, final GoogleApiClient.ConnectionCallbacks connectionCallbacks, final GoogleApiClient.OnConnectionFailedListener connectionFailedListener) { client = new GoogleApiClient.Builder(context.getApplicationContext()). addApi(Fitness.HISTORY_API). addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ)). addConnectionCallbacks(connectionCallbacks). addOnConnectionFailedListener(connectionFailedListener) .build(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Restore from saved instance state // [START restore_saved_instance_state] if (savedInstanceState != null) { mIsResolving = savedInstanceState.getBoolean(KEY_IS_RESOLVING); mShouldResolve = savedInstanceState.getBoolean(KEY_SHOULD_RESOLVE); } // [END restore_saved_instance_state] // Set up button click listeners findViewById(R.id.sign_in_button).setOnClickListener(this); findViewById(R.id.sign_out_button).setOnClickListener(this); findViewById(R.id.disconnect_button).setOnClickListener(this); // Large sign-in ((SignInButton) findViewById(R.id.sign_in_button)).setSize(SignInButton.SIZE_WIDE); // Start with sign-in button disabled until sign-in either succeeds or fails findViewById(R.id.sign_in_button).setEnabled(false); // Set up view instances mStatus = (TextView) findViewById(R.id.status); // [START create_google_api_client] // Build GoogleApiClient with access to basic profile mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(new Scope(Scopes.PROFILE)) .build(); // [END create_google_api_client] }
@Override public void onConnected(Bundle connectionHint) { mSignInClicked = false; AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(Void... params) { String accessToken = null; try { accessToken = GoogleAuthUtil.getToken(AuthActivity.this, Plus.AccountApi.getAccountName(mGoogleApiClient), "oauth2:" + Scopes.PROFILE + " " + Scopes.PLUS_LOGIN + " " + Scopes.PLUS_MOMENTS + " " + Scopes.PLUS_ME); } catch (IOException transientEx) { transientEx.printStackTrace(); } catch (UserRecoverableAuthException e) { startActivityForResult(e.getIntent(), RC_RECOVER_AUTH); } catch (GoogleAuthException authEx) { authEx.printStackTrace(); } return accessToken; } @Override protected void onPostExecute(String token) { authComplete(token); } }; task.execute(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Restore from saved instance state // [START restore_saved_instance_state] if (savedInstanceState != null) { mIsResolving = savedInstanceState.getBoolean(KEY_IS_RESOLVING); mShouldResolve = savedInstanceState.getBoolean(KEY_SHOULD_RESOLVE); } // [END restore_saved_instance_state] // Set up button click listeners findViewById(R.id.sign_in_button).setOnClickListener(this); findViewById(R.id.sign_out_button).setOnClickListener(this); findViewById(R.id.disconnect_button).setOnClickListener(this); // Large sign-in ((SignInButton) findViewById(R.id.sign_in_button)).setSize(SignInButton.SIZE_WIDE); // Start with sign-in button disabled until sign-in either succeeds or fails findViewById(R.id.sign_in_button).setEnabled(false); // Set up view instances mStatus = (TextView) findViewById(R.id.status); // [START create_google_api_client] // Build GoogleApiClient with access to basic profile mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(new Scope(Scopes.PROFILE)) .addScope(new Scope(Scopes.EMAIL)) .build(); // [END create_google_api_client] }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Views mAuthCodeTextView = findViewById(R.id.detail); // Button click listeners findViewById(R.id.sign_in_button).setOnClickListener(this); findViewById(R.id.sign_out_button).setOnClickListener(this); findViewById(R.id.disconnect_button).setOnClickListener(this); // For sample only: make sure there is a valid server client ID. validateServerClientID(); // [START configure_signin] // Configure sign-in to request offline access to the user's ID, basic // profile, and Google Drive. The first time you request a code you will // be able to exchange it for an access token and refresh token, which // you should store. In subsequent calls, the code will only result in // an access token. By asking for profile access (through // DEFAULT_SIGN_IN) you will also get an ID Token as a result of the // code exchange. String serverClientId = getString(R.string.server_client_id); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.DRIVE_APPFOLDER)) .requestServerAuthCode(serverClientId) .requestEmail() .build(); // [END configure_signin] mGoogleSignInClient = GoogleSignIn.getClient(this, gso); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Views mStatusTextView = findViewById(R.id.status); // Button listeners findViewById(R.id.sign_in_button).setOnClickListener(this); findViewById(R.id.sign_out_button).setOnClickListener(this); findViewById(R.id.disconnect_button).setOnClickListener(this); // [START configure_signin] // Configure sign-in to request the user's ID, email address, and basic // profile. ID and basic profile are included in DEFAULT_SIGN_IN. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.DRIVE_APPFOLDER)) .requestEmail() .build(); // [END configure_signin] // [START build_client] // Build a GoogleSignInClient with access to the Google Sign-In API and the // options specified by gso. mGoogleSignInClient = GoogleSignIn.getClient(this, gso); // [END build_client] // [START customize_button] // Customize sign-in button. The sign-in button can be displayed in // multiple sizes. SignInButton signInButton = findViewById(R.id.sign_in_button); signInButton.setSize(SignInButton.SIZE_STANDARD); // [END customize_button] }
@Override public void onStart() { super.onStart(); // Check if the user is already signed in and all required scopes are granted GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this); if (account != null && GoogleSignIn.hasPermissions(account, new Scope(Scopes.DRIVE_APPFOLDER))) { updateUI(account); } else { updateUI(null); } }
private void setupObjects() { FacebookSdk.sdkInitialize(getActivity()); statusBarDesigner = new StatusBarDesigner(); userSocialAuthBuilder = new UserSocialAuthBuilder(); callbackManager = CallbackManager.Factory.create(); twitterAuthClient = new TwitterAuthClient(); googleApiClient = new GoogleApiClient.Builder(getActivity()) .addConnectionCallbacks(googleConnectionCallbacks) .addOnConnectionFailedListener(googleConnectionFailedListener) .addApi(Plus.API) .addScope(new Scope(Scopes.PROFILE)) .build(); }
@Override protected String doInBackground(GoogleApiClient... clients) { if(clients.length == 0) return null; GoogleApiClient client = clients[0]; String scopes = String.format("oauth2:%s", new Scope(Scopes.PROFILE)); try { return GoogleAuthUtil.getToken(client.getContext(), Plus.AccountApi.getAccountName(client), scopes); } catch(Exception exception) { return null; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Initialize the PlusClient connection. // Scopes indicate the information about the user your application will be able to access. mPlusClient = new PlusClient.Builder(this, this, this).setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_ME).build(); }
@Inject GoogleApiClientManager(Context context) { this.connectionListener = new CompositeConnectionListener(); this.googleApiClient = new GoogleApiClient.Builder(context) .addApi(Drive.API) .addApi(Plus.API) .addScope(new Scope(Scopes.PROFILE)) .addScope(Drive.SCOPE_FILE) .addConnectionCallbacks(connectionListener) .addOnConnectionFailedListener(connectionListener) .build(); }