use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class AppEventsLoggerTests method testExplicitCallWithNoAppSettings.
public void testExplicitCallWithNoAppSettings() throws InterruptedException {
AppEventsLogger.setFlushBehavior(AppEventsLogger.FlushBehavior.EXPLICIT_ONLY);
AccessToken accessToken1 = getFakeAccessToken();
FacebookSdk.setApplicationId("234");
AppEventsLogger logger1 = AppEventsLogger.newLogger(getActivity(), accessToken1);
final WaitForBroadcastReceiver waitForBroadcastReceiver = new WaitForBroadcastReceiver();
waitForBroadcastReceiver.incrementExpectCount();
final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity());
try {
// Need to get notifications on another thread so we can wait for them.
runOnBlockerThread(new Runnable() {
@Override
public void run() {
broadcastManager.registerReceiver(waitForBroadcastReceiver, new IntentFilter(AppEventsLogger.ACTION_APP_EVENTS_FLUSHED));
}
}, true);
logger1.logEvent("an_event");
logger1.flush();
waitForBroadcastReceiver.waitForExpectedCalls();
closeBlockerAndAssertSuccess();
} finally {
broadcastManager.unregisterReceiver(waitForBroadcastReceiver);
}
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class AppEventsLoggerTests method testSimpleCall.
public void testSimpleCall() throws InterruptedException {
AppEventsLogger.setFlushBehavior(AppEventsLogger.FlushBehavior.EXPLICIT_ONLY);
AccessToken accessToken1 = getAccessTokenForSharedUser();
AccessToken accessToken2 = getAccessTokenForSharedUser(SECOND_TEST_USER_TAG);
AppEventsLogger logger1 = AppEventsLogger.newLogger(getActivity(), accessToken1);
AppEventsLogger logger2 = AppEventsLogger.newLogger(getActivity(), accessToken2);
final WaitForBroadcastReceiver waitForBroadcastReceiver = new WaitForBroadcastReceiver();
waitForBroadcastReceiver.incrementExpectCount();
final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity());
try {
// Need to get notifications on another thread so we can wait for them.
runOnBlockerThread(new Runnable() {
@Override
public void run() {
broadcastManager.registerReceiver(waitForBroadcastReceiver, new IntentFilter(AppEventsLogger.ACTION_APP_EVENTS_FLUSHED));
}
}, true);
logger1.logEvent("an_event");
logger2.logEvent("another_event");
// test illegal event name and event key, should not crash in non-debug environment.
logger1.logEvent("$illegal_event_name");
Bundle params = new Bundle();
params.putString("illegal%key", "good_value");
logger1.logEvent("legal_event_name", params);
char[] val = { 'b', 'a', 'd' };
params.putCharArray("legal_key", val);
logger1.logEvent("legal_event", params);
logger1.flush();
waitForBroadcastReceiver.waitForExpectedCalls();
closeBlockerAndAssertSuccess();
} finally {
broadcastManager.unregisterReceiver(waitForBroadcastReceiver);
}
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class ShareApi method sharePhotoContent.
private void sharePhotoContent(final SharePhotoContent photoContent, final FacebookCallback<Sharer.Result> callback) {
final Mutable<Integer> requestCount = new Mutable<Integer>(0);
final AccessToken accessToken = AccessToken.getCurrentAccessToken();
final ArrayList<GraphRequest> requests = new ArrayList<GraphRequest>();
final ArrayList<JSONObject> results = new ArrayList<JSONObject>();
final ArrayList<GraphResponse> errorResponses = new ArrayList<GraphResponse>();
final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
final JSONObject result = response.getJSONObject();
if (result != null) {
results.add(result);
}
if (response.getError() != null) {
errorResponses.add(response);
}
requestCount.value -= 1;
if (requestCount.value == 0) {
if (!errorResponses.isEmpty()) {
ShareInternalUtility.invokeCallbackWithResults(callback, null, errorResponses.get(0));
} else if (!results.isEmpty()) {
final String postId = results.get(0).optString("id");
ShareInternalUtility.invokeCallbackWithResults(callback, postId, response);
}
}
}
};
try {
for (SharePhoto photo : photoContent.getPhotos()) {
Bundle params;
try {
params = getSharePhotoCommonParameters(photo, photoContent);
} catch (JSONException e) {
ShareInternalUtility.invokeCallbackWithException(callback, e);
return;
}
final Bitmap bitmap = photo.getBitmap();
final Uri photoUri = photo.getImageUrl();
String caption = photo.getCaption();
if (caption == null) {
caption = this.getMessage();
}
if (bitmap != null) {
requests.add(GraphRequest.newUploadPhotoRequest(accessToken, getGraphPath(PHOTOS_EDGE), bitmap, caption, params, requestCallback));
} else if (photoUri != null) {
requests.add(GraphRequest.newUploadPhotoRequest(accessToken, getGraphPath(PHOTOS_EDGE), photoUri, caption, params, requestCallback));
}
}
requestCount.value += requests.size();
for (GraphRequest request : requests) {
request.executeAsync();
}
} catch (final FileNotFoundException ex) {
ShareInternalUtility.invokeCallbackWithException(callback, ex);
}
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class ShareDialog method canShowWebTypeCheck.
private static boolean canShowWebTypeCheck(Class<? extends ShareContent> contentType) {
// If we don't have an instance of a ShareContent, then all we can do is check whether
// this is a ShareLinkContent, which can be shared if configured properly.
// The instance method version of this check is more accurate and should be used on
// ShareDialog instances.
// SharePhotoContent currently requires the user staging endpoint, so we need a user access
// token, so we need to see if we have one
final AccessToken accessToken = AccessToken.getCurrentAccessToken();
final boolean haveUserAccessToken = accessToken != null && !accessToken.isExpired();
return ShareLinkContent.class.isAssignableFrom(contentType) || ShareOpenGraphContent.class.isAssignableFrom(contentType) || (SharePhotoContent.class.isAssignableFrom(contentType) && haveUserAccessToken);
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class LoginClientTests method testReauthorizationWithSameFbidSucceeds.
@LargeTest
public void testReauthorizationWithSameFbidSucceeds() throws Exception {
TestBlocker blocker = getTestBlocker();
MockValidatingLoginClient client = new MockValidatingLoginClient(null, blocker);
client.addAccessTokenToFbidMapping(USER_1_ACCESS_TOKEN, USER_1_FBID);
client.addAccessTokenToFbidMapping(USER_2_ACCESS_TOKEN, USER_2_FBID);
client.setPermissionsToReport(PERMISSIONS);
LoginClient.Request request = createNewPermissionRequest();
client.setRequest(request);
AccessToken token = new AccessToken(USER_1_ACCESS_TOKEN, APP_ID, USER_1_FBID, PERMISSIONS, null, null, null, null);
AccessToken.setCurrentAccessToken(token);
LoginClient.Result result = LoginClient.Result.createTokenResult(request, token);
client.completeAndValidate(result);
blocker.waitForSignals(1);
assertNotNull(client.result);
assertEquals(LoginClient.Result.Code.SUCCESS, client.result.code);
AccessToken resultToken = client.result.token;
assertNotNull(resultToken);
assertEquals(USER_1_ACCESS_TOKEN, resultToken.getToken());
// We don't care about ordering.
assertEquals(new HashSet<String>(PERMISSIONS), new HashSet<String>(resultToken.getPermissions()));
}
Aggregations