Search in sources :

Example 1 with SocialMediaCredentials

use of cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaCredentials in project androidApp by InspectorIncognito.

the class FacebookDataManager method getCredentials.

void getCredentials(final CredentialsListener listener) {
    Log.d(TAG, "getUserData");
    final AccessToken currentToken = AccessToken.getCurrentAccessToken();
    GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), "/me", null, HttpMethod.GET, new GraphRequest.Callback() {

        public void onCompleted(GraphResponse response) {
            try {
                Profile profile = Profile.getCurrentProfile();
                String email = response.getJSONObject().getString("email");
                String name = response.getJSONObject().getString("name");
                String imageUri = profile.getProfilePictureUri(200, 200).toString();
                SocialMediaCredentials credentials = new SocialMediaCredentials(currentToken.getToken(), currentToken.getUserId(), FACEBOOK_ACCOUNT, name, email, imageUri);
                listener.onSuccess(new FacebookAccount(credentials));
            } catch (JSONException | NullPointerException e) {
                listener.onError(new ServerStatusCode(ServerStatusCode.LOGIN_API_ERROR));
                Log.e(TAG, e.getMessage() == null ? "null message" : e.getMessage());
            }
        }
    });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,email");
    request.setParameters(parameters);
    request.executeAsync();
}
Also used : GraphRequest(com.facebook.GraphRequest) GraphResponse(com.facebook.GraphResponse) AccessToken(com.facebook.AccessToken) Bundle(android.os.Bundle) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) SocialMediaCredentials(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaCredentials) Profile(com.facebook.Profile)

Example 2 with SocialMediaCredentials

use of cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaCredentials in project androidApp by InspectorIncognito.

the class GoogleDataManager method getCredentials.

void getCredentials(final CredentialsListener listener, GoogleSignInAccount account, GoogleApiClient mGoogleApiClient) {
    Log.d(TAG, "getUserData");
    SocialMediaCredentials credentials = new SocialMediaCredentials(account.getIdToken(), account.getId(), GOOGLE_ACCOUNT, account.getDisplayName(), account.getEmail(), account.getPhotoUrl().toString());
    listener.onSuccess(new GoogleAccount(credentials, mGoogleApiClient));
}
Also used : SocialMediaCredentials(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaCredentials)

Aggregations

SocialMediaCredentials (cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaCredentials)2 Bundle (android.os.Bundle)1 ServerStatusCode (cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)1 AccessToken (com.facebook.AccessToken)1 GraphRequest (com.facebook.GraphRequest)1 GraphResponse (com.facebook.GraphResponse)1 Profile (com.facebook.Profile)1