本文整理汇总了Java中com.facebook.android.Facebook类的典型用法代码示例。如果您正苦于以下问题:Java Facebook类的具体用法?Java Facebook怎么用?Java Facebook使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Facebook类属于com.facebook.android包,在下文中一共展示了Facebook类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.facebook.android.Facebook; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
//ALog.m();
super.onCreate(savedInstanceState);
mFacebook = new Facebook();
if ( mFacebook.isSessionValid() ) {
//ALog.i("Already have a saved Facebook session, skipping authorization.");
setResult(RESULT_OK);
finish();
return;
}
mFacebook.authorize(this, FacebookConfig.getAppId(), PERMISSIONS, new LoginDialogListener());
//setContentView(R.layout.facebook);
}
示例2: startFacebookWebViewActivity
import com.facebook.android.Facebook; //导入依赖的package包/类
private void startFacebookWebViewActivity() {
Intent intent = new Intent(this, FacebookWebViewActivity.class);
intent.putExtra(FacebookWebViewActivity.INTENT_EXTRA_ACTION, Facebook.LOGIN);
intent.putExtra(FacebookWebViewActivity.INTENT_EXTRA_KEY_APP_ID,
getResources().getString(R.string.facebook_api_key));
intent.putExtra(FacebookWebViewActivity.INTENT_EXTRA_KEY_PERMISSIONS,
new String[] {}); //{"publish_stream", "read_stream", "offline_access"});
intent.putExtra(FacebookWebViewActivity.INTENT_EXTRA_KEY_DEBUG, false);
intent.putExtra(FacebookWebViewActivity.INTENT_EXTRA_KEY_CLEAR_COOKIES, true);
startActivityForResult(intent, ACTIVITY_RESULT_FACEBOOK_WEBVIEW_ACTIVITY);
}
示例3: onActivityResult
import com.facebook.android.Facebook; //导入依赖的package包/类
/**
* Listen for FacebookWebViewActivity finishing, inspect success/failure and returned
* request parameters.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ACTIVITY_RESULT_FACEBOOK_WEBVIEW_ACTIVITY) {
// If RESULT_OK, means the request was attempted, but we still have to check the return status.
if (resultCode == RESULT_OK) {
// Check return status.
if (data.getBooleanExtra(FacebookWebViewActivity.INTENT_RESULT_KEY_RESULT_STATUS, false)) {
// If ok, the result bundle will contain all data from the webview.
Bundle bundle = data.getBundleExtra(FacebookWebViewActivity.INTENT_RESULT_KEY_RESULT_BUNDLE);
// We can switch on the action here, the activity echoes it back to us for convenience.
String suppliedAction = data.getStringExtra(FacebookWebViewActivity.INTENT_RESULT_KEY_SUPPLIED_ACTION);
if (suppliedAction.equals(Facebook.LOGIN)) {
// We can now start a task to fetch foursquare friends using their facebook id.
mStateHolder.startTaskFindFriends(
AddFriendsByUserInputActivity.this, bundle.getString(Facebook.TOKEN));
}
} else {
// Error running the operation, report to user perhaps.
String error = data.getStringExtra(FacebookWebViewActivity.INTENT_RESULT_KEY_ERROR);
Log.e(TAG, error);
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
finish();
}
} else {
// If the user cancelled enterting their facebook credentials, exit here too.
finish();
}
}
}
示例4: clearFacebookCredentials
import com.facebook.android.Facebook; //导入依赖的package包/类
public static void clearFacebookCredentials(Facebook facebook, Context context) {
if(facebook.isSessionValid())
facebook.getSession().close();
Editor editor = context.getSharedPreferences(FACEBOOK_KEY, Context.MODE_PRIVATE).edit();
editor.remove(FACEBOOK_TOKEN);
editor.commit();
}
示例5: FacebookConnector
import com.facebook.android.Facebook; //导入依赖的package包/类
public FacebookConnector(String appId, String[] permissions, SocialActivity socialActivity) {
this.facebook = new Facebook(appId);
SharedPreferencesCredentialStore.restoreFacebookSession(facebook, socialActivity.getApplicationContext());
this.permissions=permissions;
this.mHandler = new Handler();
this.activity = socialActivity;
socialActivity.registerSocialConnector(this);
}
示例6: shareFacebook
import com.facebook.android.Facebook; //导入依赖的package包/类
public void shareFacebook(){
facebook = new Facebook("1418005058449444");
restoreCredentials(facebook);
messageToPost = "Hello Everyone.";
if (!facebook.isSessionValid()) {
loginAndPostToWall();
} else {
postToWall(messageToPost);
}
}
示例7: save
import com.facebook.android.Facebook; //导入依赖的package包/类
public static boolean save(Facebook session, Context context) {
Editor editor =
context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
editor.putString(TOKEN, session.getAccessToken());
editor.putLong(EXPIRES, session.getAccessExpires());
return editor.commit();
}
示例8: restore
import com.facebook.android.Facebook; //导入依赖的package包/类
public static boolean restore(Facebook session, Context context) {
SharedPreferences savedSession =
context.getSharedPreferences(KEY, Context.MODE_PRIVATE);
session.setAccessToken(savedSession.getString(TOKEN, null));
session.setAccessExpires(savedSession.getLong(EXPIRES, 0));
return session.isSessionValid();
}
示例9: makeWallPost
import com.facebook.android.Facebook; //导入依赖的package包/类
private void makeWallPost() {
//ALog.m();
Facebook facebook = new Facebook();
SessionStore.restore(facebook, this);
//ALog.i("stream.publish parameters: ", mParams);
facebook.dialog(FacebookApplicationPost.this, "stream.publish", mParams,
new WallPostDialogListener());
}
示例10: onComplete
import com.facebook.android.Facebook; //导入依赖的package包/类
@Override
public void onComplete(Bundle values) {
//Log.i("got values", values.toString());
accessToken = values.getString(Facebook.TOKEN);
// TODO Auto-generated method stub
}
示例11: testPublicApi
import com.facebook.android.Facebook; //导入依赖的package包/类
public boolean testPublicApi() {
Facebook fb = new Facebook(APP_ID);
try {
Log.d("Tests", "Testing standard API call");
JSONObject response = Util.parseJson(fb.request("4"));
if (!response.getString("name").equals("Mark Zuckerberg")) {
return false;
}
Log.d("Tests", "Testing an API call with a specific method");
response = Util.parseJson(
fb.request("soneff", new Bundle(), "GET"));
if (!response.getString("name").equals("Steven Soneff")) {
return false;
}
Log.d("Tests", "Testing a public search query");
Bundle params = new Bundle();
params.putString("q", "facebook");
response = Util.parseJson(fb.request("search", params));
if (response.getJSONArray("data").length() == 0) return false;
Log.d("Tests", "Public API Tests passed");
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
示例12: restoreFacebookSession
import com.facebook.android.Facebook; //导入依赖的package包/类
public static boolean restoreFacebookSession(Facebook facebook, Context context) {
SharedPreferences savedSession = context.getSharedPreferences(FACEBOOK_KEY, Context.MODE_PRIVATE);
facebook.setAccessToken(savedSession.getString(FACEBOOK_TOKEN, null));
facebook.setAccessExpires(savedSession.getLong(EXPIRES, 0));
return facebook.isSessionValid();
}
示例13: saveFacebookToken
import com.facebook.android.Facebook; //导入依赖的package包/类
public static boolean saveFacebookToken(Facebook session, Context context) {
Editor editor = context.getSharedPreferences(FACEBOOK_KEY, Context.MODE_PRIVATE).edit();
editor.putString(FACEBOOK_TOKEN, session.getAccessToken());
editor.putLong(EXPIRES, session.getAccessExpires());
return editor.commit();
}
示例14: forceAuthenticate
import com.facebook.android.Facebook; //导入依赖的package包/类
public void forceAuthenticate() {
facebook.authorize(this.activity, this.permissions, Facebook.FORCE_DIALOG_AUTH,new LoginDialogListener());
}
示例15: getFacebook
import com.facebook.android.Facebook; //导入依赖的package包/类
public Facebook getFacebook() {
return this.facebook;
}