Java Code Examples for com.facebook.internal.Utility#getMetadataApplicationId()

The following examples show how to use com.facebook.internal.Utility#getMetadataApplicationId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginButton.java    From facebook-api-android-maven with Apache License 2.0 6 votes vote down vote up
private boolean initializeActiveSessionWithCachedToken(Context context) {
    if (context == null) {
        return false;
    }

    Session session = Session.getActiveSession();
    if (session != null) {
        return session.isOpened();
    }

    String applicationId = Utility.getMetadataApplicationId(context);
    if (applicationId == null) {
        return false;
    }

    return Session.openActiveSessionFromCache(context) != null;
}
 
Example 2
Source File: LoginButton.java    From android-skeleton-project with MIT License 6 votes vote down vote up
private boolean initializeActiveSessionWithCachedToken(Context context) {
    if (context == null) {
        return false;
    }

    Session session = Session.getActiveSession();
    if (session != null) {
        return session.isOpened();
    }

    String applicationId = Utility.getMetadataApplicationId(context);
    if (applicationId == null) {
        return false;
    }

    return Session.openActiveSessionFromCache(context) != null;
}
 
Example 3
Source File: LoginButton.java    From Abelana-Android with Apache License 2.0 6 votes vote down vote up
private boolean initializeActiveSessionWithCachedToken(Context context) {
    if (context == null) {
        return false;
    }

    Session session = Session.getActiveSession();
    if (session != null) {
        return session.isOpened();
    }

    String applicationId = Utility.getMetadataApplicationId(context);
    if (applicationId == null) {
        return false;
    }

    return Session.openActiveSessionFromCache(context) != null;
}
 
Example 4
Source File: LoginButton.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 6 votes vote down vote up
private boolean initializeActiveSessionWithCachedToken(Context context) {
    if (context == null) {
        return false;
    }

    Session session = Session.getActiveSession();
    if (session != null) {
        return session.isOpened();
    }

    String applicationId = Utility.getMetadataApplicationId(context);
    if (applicationId == null) {
        return false;
    }

    return Session.openActiveSessionFromCache(context) != null;
}
 
Example 5
Source File: LoginButton.java    From Klyph with MIT License 6 votes vote down vote up
private boolean initializeActiveSessionWithCachedToken(Context context) {
    if (context == null) {
        return false;
    }

    Session session = Session.getActiveSession();
    if (session != null) {
        return session.isOpened();
    }

    String applicationId = Utility.getMetadataApplicationId(context);
    if (applicationId == null) {
        return false;
    }

    return Session.openActiveSessionFromCache(context) != null;
}
 
Example 6
Source File: WebDialog.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
protected BuilderBase(Context context, String applicationId, String action, Bundle parameters) {
    if (applicationId == null) {
        applicationId = Utility.getMetadataApplicationId(context);
    }
    Validate.notNullOrEmpty(applicationId, "applicationId");
    this.applicationId = applicationId;

    finishInit(context, action, parameters);
}
 
Example 7
Source File: FacebookDialog.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
Builder(Activity activity) {
    Validate.notNull(activity, "activity");

    this.activity = activity;
    applicationId = Utility.getMetadataApplicationId(activity);
    appCall = new PendingCall(NativeProtocol.DIALOG_REQUEST_CODE);
}
 
Example 8
Source File: WebDialog.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
protected BuilderBase(Context context, String action) {
    Session activeSession = Session.getActiveSession();
    if (activeSession != null && activeSession.isOpened()) {
        this.session = activeSession;
    } else {
        String applicationId = Utility.getMetadataApplicationId(context);
        if (applicationId != null) {
            this.applicationId = applicationId;
        } else {
            throw new FacebookException("Attempted to create a builder without an open" +
                    " Active Session or a valid default Application ID.");
        }
    }
    finishInit(context, action, null);
}
 
Example 9
Source File: WebDialog.java    From android-skeleton-project with MIT License 5 votes vote down vote up
protected BuilderBase(Context context, String applicationId, String action, Bundle parameters) {
    if (applicationId == null) {
        applicationId = Utility.getMetadataApplicationId(context);
    }
    Validate.notNullOrEmpty(applicationId, "applicationId");
    this.applicationId = applicationId;

    finishInit(context, action, parameters);
}
 
Example 10
Source File: FacebookDialog.java    From Klyph with MIT License 5 votes vote down vote up
Builder(Activity activity) {
    Validate.notNull(activity, "activity");

    this.activity = activity;
    applicationId = Utility.getMetadataApplicationId(activity);
    appCall = new PendingCall(NativeProtocol.DIALOG_REQUEST_CODE);
}
 
Example 11
Source File: FacebookDialog.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param activity the Activity which is presenting the native Share dialog; must not be null
 */
public Builder(Activity activity) {
    Validate.notNull(activity, "activity");

    this.activity = activity;
    applicationId = Utility.getMetadataApplicationId(activity);
    appCall = new PendingCall(NativeProtocol.DIALOG_REQUEST_CODE);
}
 
Example 12
Source File: AppEventsLogger.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor is private, newLogger() methods should be used to build an instance.
 */
private AppEventsLogger(Context context, String applicationId, Session session) {

    Validate.notNull(context, "context");
    this.context = context;

    if (session == null) {
        session = Session.getActiveSession();
    }

    // If we have a session and the appId passed is null or matches the session's app ID:
    if (session != null &&
            (applicationId == null || applicationId.equals(session.getApplicationId()))
            ) {
        accessTokenAppId = new AccessTokenAppIdPair(session);
    } else {
        // If no app ID passed, get it from the manifest:
        if (applicationId == null) {
            applicationId = Utility.getMetadataApplicationId(context);
        }
        accessTokenAppId = new AccessTokenAppIdPair(null, applicationId);
    }

    synchronized (staticLock) {

        if (hashedDeviceAndAppId == null) {
            hashedDeviceAndAppId = Utility.getHashedDeviceAndAppID(context, applicationId);
        }

        if (applicationContext == null) {
            applicationContext = context.getApplicationContext();
        }
    }

    initializeTimersIfNeeded();
}
 
Example 13
Source File: FacebookDialog.java    From platform-friends-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Builder(Activity activity) {
    Validate.notNull(activity, "activity");

    this.activity = activity;
    applicationId = Utility.getMetadataApplicationId(activity);
    appCall = new PendingCall(NativeProtocol.DIALOG_REQUEST_CODE);
}
 
Example 14
Source File: LoginButton.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private void checkToolTipSettings() {
    switch (toolTipMode) {
        case AUTOMATIC:
            // kick off an async request
            final String appId = Utility.getMetadataApplicationId(getContext());
            FacebookSdk.getExecutor().execute(new Runnable() {
                @Override
                public void run() {
                    final FetchedAppSettings settings = Utility.queryAppSettings(appId, false);
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            showToolTipPerSettings(settings);
                        }
                    });
                }
            });
            break;
        case DISPLAY_ALWAYS:
            String toolTipString = getResources().getString(
                    R.string.com_facebook_tooltip_default);
            displayToolTip(toolTipString);
            break;
        case NEVER_DISPLAY:
            break;
    }
}
 
Example 15
Source File: Request.java    From Klyph with MIT License 4 votes vote down vote up
/**
 * Creates a new Request configured to retrieve an App User ID for the app's Facebook user.  Callers
 * will send this ID back to their own servers, collect up a set to create a Facebook Custom Audience with,
 * and then use the resultant Custom Audience to target ads.
 * <p/>
 * The GraphObject in the response will include an "custom_audience_third_party_id" property, with the value
 * being the ID retrieved.  This ID is an encrypted encoding of the Facebook user's ID and the
 * invoking Facebook app ID.  Multiple calls with the same user will return different IDs, thus these IDs cannot be
 * used to correlate behavior across devices or applications, and are only meaningful when sent back to Facebook
 * for creating Custom Audiences.
 * <p/>
 * The ID retrieved represents the Facebook user identified in the following way: if the specified session
 * (or activeSession if the specified session is `null`) is open, the ID will represent the user associated with
 * the activeSession; otherwise the ID will represent the user logged into the native Facebook app on the device.
 * A `null` ID will be provided into the callback if a) there is no native Facebook app, b) no one is logged into
 * it, or c) the app has previously called
 * {@link Settings#setLimitEventAndDataUsage(android.content.Context, boolean)} ;} with `true` for this user.
 *
 * @param session
 *            the Session to issue the Request on, or null; if non-null, the session must be in an opened state.
 *            If there is no logged-in Facebook user, null is the expected choice.
 * @param context
 *            the Application context from which the app ID will be pulled, and from which the 'attribution ID'
 *            for the Facebook user is determined.  If there has been no app ID set, an exception will be thrown.
 * @param applicationId
 *            explicitly specified Facebook App ID.  If null, and there's a valid session, then the application ID
 *            from the session will be used, otherwise the application ID from metadata will be used.
 * @param callback
 *            a callback that will be called when the request is completed to handle success or error conditions.
 *            The GraphObject in the Response will contain a "custom_audience_third_party_id" property that
 *            represents the user as described above.
 * @return a Request that is ready to execute
 */
public static Request newCustomAudienceThirdPartyIdRequest(Session session,
        Context context, String applicationId, Callback callback) {

    // if provided session or activeSession is opened, use it.
    if (session == null) {
        session = Session.getActiveSession();
    }

    if (session != null && !session.isOpened()) {
        session = null;
    }

    if (applicationId == null) {
        if (session != null) {
            applicationId = session.getApplicationId();
        } else {
            applicationId = Utility.getMetadataApplicationId(context);
        }
    }

    if (applicationId == null) {
        throw new FacebookException("Facebook App ID cannot be determined");
    }

    String endpoint = applicationId + "/custom_audience_third_party_id";

    Bundle parameters = new Bundle();
    if (session == null) {
        // Only use the attributionID if we don't have an open session.  If we do have an open session, then
        // the user token will be used to identify the user, and is more reliable than the attributionID.
        String attributionId = Settings.getAttributionId(context.getContentResolver());
        if (attributionId != null) {
            parameters.putString("udid", attributionId);
        }
    }

    // Server will choose to not provide the App User ID in the event that event usage has been limited for
    // this user for this app.
    if (Settings.getLimitEventAndDataUsage(context)) {
        parameters.putString("limit_event_usage", "1");
    }

    return new Request(session, endpoint, parameters, HttpMethod.GET, callback);
}
 
Example 16
Source File: Session.java    From KlyphMessenger with MIT License 4 votes vote down vote up
Session(Context context, String applicationId, TokenCachingStrategy tokenCachingStrategy,
        boolean loadTokenFromCache) {
    // if the application ID passed in is null, try to get it from the
    // meta-data in the manifest.
    if ((context != null) && (applicationId == null)) {
        applicationId = Utility.getMetadataApplicationId(context);
    }

    Validate.notNull(applicationId, "applicationId");

    initializeStaticContext(context);

    if (tokenCachingStrategy == null) {
        tokenCachingStrategy = new SharedPreferencesTokenCachingStrategy(staticContext);
    }

    this.applicationId = applicationId;
    this.tokenCachingStrategy = tokenCachingStrategy;
    this.state = SessionState.CREATED;
    this.pendingAuthorizationRequest = null;
    this.callbacks = new ArrayList<StatusCallback>();
    this.handler = new Handler(Looper.getMainLooper());

    Bundle tokenState = loadTokenFromCache ? tokenCachingStrategy.load() : null;
    if (TokenCachingStrategy.hasTokenInformation(tokenState)) {
        Date cachedExpirationDate = TokenCachingStrategy
                .getDate(tokenState, TokenCachingStrategy.EXPIRATION_DATE_KEY);
        Date now = new Date();

        if ((cachedExpirationDate == null) || cachedExpirationDate.before(now)) {
            // If expired or we require new permissions, clear out the
            // current token cache.
            tokenCachingStrategy.clear();
            this.tokenInfo = AccessToken.createEmptyToken(Collections.<String>emptyList());
        } else {
            // Otherwise we have a valid token, so use it.
            this.tokenInfo = AccessToken.createFromCache(tokenState);
            this.state = SessionState.CREATED_TOKEN_LOADED;
        }
    } else {
        this.tokenInfo = AccessToken.createEmptyToken(Collections.<String>emptyList());
    }
}
 
Example 17
Source File: Session.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 4 votes vote down vote up
Session(Context context, String applicationId, TokenCachingStrategy tokenCachingStrategy,
        boolean loadTokenFromCache) {
    // if the application ID passed in is null, try to get it from the
    // meta-data in the manifest.
    if ((context != null) && (applicationId == null)) {
        applicationId = Utility.getMetadataApplicationId(context);
    }

    Validate.notNull(applicationId, "applicationId");

    initializeStaticContext(context);

    if (tokenCachingStrategy == null) {
        tokenCachingStrategy = new SharedPreferencesTokenCachingStrategy(staticContext);
    }

    this.applicationId = applicationId;
    this.tokenCachingStrategy = tokenCachingStrategy;
    this.state = SessionState.CREATED;
    this.pendingRequest = null;
    this.callbacks = new ArrayList<StatusCallback>();
    this.handler = new Handler(Looper.getMainLooper());

    Bundle tokenState = loadTokenFromCache ? tokenCachingStrategy.load() : null;
    if (TokenCachingStrategy.hasTokenInformation(tokenState)) {
        Date cachedExpirationDate = TokenCachingStrategy
                .getDate(tokenState, TokenCachingStrategy.EXPIRATION_DATE_KEY);
        Date now = new Date();

        if ((cachedExpirationDate == null) || cachedExpirationDate.before(now)) {
            // If expired or we require new permissions, clear out the
            // current token cache.
            tokenCachingStrategy.clear();
            this.tokenInfo = AccessToken.createEmptyToken(Collections.<String>emptyList());
        } else {
            // Otherwise we have a valid token, so use it.
            this.tokenInfo = AccessToken.createFromCache(tokenState);
            this.state = SessionState.CREATED_TOKEN_LOADED;
        }
    } else {
        this.tokenInfo = AccessToken.createEmptyToken(Collections.<String>emptyList());
    }
}
 
Example 18
Source File: Request.java    From platform-friends-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Creates a new Request configured to retrieve an App User ID for the app's Facebook user.  Callers
 * will send this ID back to their own servers, collect up a set to create a Facebook Custom Audience with,
 * and then use the resultant Custom Audience to target ads.
 * <p/>
 * The GraphObject in the response will include an "custom_audience_third_party_id" property, with the value
 * being the ID retrieved.  This ID is an encrypted encoding of the Facebook user's ID and the
 * invoking Facebook app ID.  Multiple calls with the same user will return different IDs, thus these IDs cannot be
 * used to correlate behavior across devices or applications, and are only meaningful when sent back to Facebook
 * for creating Custom Audiences.
 * <p/>
 * The ID retrieved represents the Facebook user identified in the following way: if the specified session
 * (or activeSession if the specified session is `null`) is open, the ID will represent the user associated with
 * the activeSession; otherwise the ID will represent the user logged into the native Facebook app on the device.
 * A `null` ID will be provided into the callback if a) there is no native Facebook app, b) no one is logged into
 * it, or c) the app has previously called
 * {@link Settings#setLimitEventAndDataUsage(android.content.Context, boolean)} ;} with `true` for this user.
 *
 * @param session
 *            the Session to issue the Request on, or null; if non-null, the session must be in an opened state.
 *            If there is no logged-in Facebook user, null is the expected choice.
 * @param context
 *            the Application context from which the app ID will be pulled, and from which the 'attribution ID'
 *            for the Facebook user is determined.  If there has been no app ID set, an exception will be thrown.
 * @param applicationId
 *            explicitly specified Facebook App ID.  If null, and there's a valid session, then the application ID
 *            from the session will be used, otherwise the application ID from metadata will be used.
 * @param callback
 *            a callback that will be called when the request is completed to handle success or error conditions.
 *            The GraphObject in the Response will contain a "custom_audience_third_party_id" property that
 *            represents the user as described above.
 * @return a Request that is ready to execute
 */
public static Request newCustomAudienceThirdPartyIdRequest(Session session,
        Context context, String applicationId, Callback callback) {

    // if provided session or activeSession is opened, use it.
    if (session == null) {
        session = Session.getActiveSession();
    }

    if (session != null && !session.isOpened()) {
        session = null;
    }

    if (applicationId == null) {
        if (session != null) {
            applicationId = session.getApplicationId();
        } else {
            applicationId = Utility.getMetadataApplicationId(context);
        }
    }

    if (applicationId == null) {
        throw new FacebookException("Facebook App ID cannot be determined");
    }

    String endpoint = applicationId + "/custom_audience_third_party_id";

    Bundle parameters = new Bundle();
    if (session == null) {
        // Only use the attributionID if we don't have an open session.  If we do have an open session, then
        // the user token will be used to identify the user, and is more reliable than the attributionID.
        String attributionId = Settings.getAttributionId(context.getContentResolver());
        if (attributionId != null) {
            parameters.putString("udid", attributionId);
        }
    }

    // Server will choose to not provide the App User ID in the event that event usage has been limited for
    // this user for this app.
    if (Settings.getLimitEventAndDataUsage(context)) {
        parameters.putString("limit_event_usage", "1");
    }

    return new Request(session, endpoint, parameters, HttpMethod.GET, callback);
}
 
Example 19
Source File: AppLinkData.java    From platform-friends-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Asynchronously fetches app link information that might have been stored for use
 * after installation of the app
 * @param context The context
 * @param applicationId Facebook application Id. If null, it is taken from the manifest
 * @param completionHandler CompletionHandler to be notified with the AppLinkData object or null if none is
 *                          available.  Must not be null.
 */
public static void fetchDeferredAppLinkData(
        Context context,
        String applicationId,
        final CompletionHandler completionHandler) {
    Validate.notNull(context, "context");
    Validate.notNull(completionHandler, "completionHandler");

    if (applicationId == null) {
        applicationId = Utility.getMetadataApplicationId(context);
    }

    Validate.notNull(applicationId, "applicationId");

    DeferredAppLinkDataClient client = new DeferredAppLinkDataClient(context, applicationId);
    DeferredAppLinkDataClient.CompletedListener callback = new DeferredAppLinkDataClient.CompletedListener() {
        @Override
        public void completed(Bundle result) {
            AppLinkData appLinkData = null;
            if (result != null) {
                final String appLinkArgsJsonString = result.getString(BUNDLE_APPLINK_ARGS_KEY);
                final long tapTimeUtc = result.getLong(ARGUMENTS_TAPTIME_KEY, -1);

                // Now create the app link
                appLinkData = createFromJson(appLinkArgsJsonString);
                if (tapTimeUtc != -1) {
                    try {
                        appLinkData.getArguments().put(ARGUMENTS_TAPTIME_KEY, tapTimeUtc);
                    } catch (JSONException e) {
                        Log.d(TAG, "Unable to put tap time in AppLinkData.arguments");
                    }
                }
            }
            completionHandler.onDeferredAppLinkDataFetched(appLinkData);
        }
    };
    client.setCompletedListener(callback);

    if (!client.start()) {
        // there is not a sufficient version of fb4a present to return a deferred app link, so kick off
        // a call to the completion handler.
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                completionHandler.onDeferredAppLinkDataFetched(null);
            }
        });
    }
}
 
Example 20
Source File: Session.java    From facebook-api-android-maven with Apache License 2.0 4 votes vote down vote up
Session(Context context, String applicationId, TokenCachingStrategy tokenCachingStrategy,
        boolean loadTokenFromCache) {
    // if the application ID passed in is null, try to get it from the
    // meta-data in the manifest.
    if ((context != null) && (applicationId == null)) {
        applicationId = Utility.getMetadataApplicationId(context);
    }

    Validate.notNull(applicationId, "applicationId");

    initializeStaticContext(context);

    if (tokenCachingStrategy == null) {
        tokenCachingStrategy = new SharedPreferencesTokenCachingStrategy(staticContext);
    }

    this.applicationId = applicationId;
    this.tokenCachingStrategy = tokenCachingStrategy;
    this.state = SessionState.CREATED;
    this.pendingAuthorizationRequest = null;
    this.callbacks = new ArrayList<StatusCallback>();
    this.handler = new Handler(Looper.getMainLooper());

    Bundle tokenState = loadTokenFromCache ? tokenCachingStrategy.load() : null;
    if (TokenCachingStrategy.hasTokenInformation(tokenState)) {
        Date cachedExpirationDate = TokenCachingStrategy
                .getDate(tokenState, TokenCachingStrategy.EXPIRATION_DATE_KEY);
        Date now = new Date();

        if ((cachedExpirationDate == null) || cachedExpirationDate.before(now)) {
            // If expired or we require new permissions, clear out the
            // current token cache.
            tokenCachingStrategy.clear();
            this.tokenInfo = AccessToken.createEmptyToken();
        } else {
            // Otherwise we have a valid token, so use it.
            this.tokenInfo = AccessToken.createFromCache(tokenState);
            this.state = SessionState.CREATED_TOKEN_LOADED;
        }
    } else {
        this.tokenInfo = AccessToken.createEmptyToken();
    }
}