This module makes easier to use a main Facebook features (login & share)
- Main Application class:
public class App extends Application {
private static final String FACEBOOK_APP_ID = "APP ID from Facebook Developer Console";
..........
@Override
public void onCreate() {
super.onCreate();
//init facebook helper
FBLoginShareHelper.getInstance().init(this, FACEBOOK_APP_ID);
}
}
- App-level build.gradle
dependencies {
...............
...............
compile project(':facebook-login-share')
}
- Start login from fragment:
FBLoginShareHelper.getInstance().loginAsPageAdmin(fragment, new IFBLoginShareHelper.IFBLoginResultCallbacks() {
@Override
public void onSuccess(String accessToken, final String userOrPageName, String userOrPageId) {
//here your code
}
@Override
public void onFail(String message) {
//show error
Toast.makeText(mView.getActivity(), message, Toast.LENGTH_SHORT).show();
}
});
- Handle result from onActivityResult() in the fragment:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
................
................
................
case FBLoginShareHelper.REQUEST_CODE:
FBLoginShareHelper.getInstance().onLoginResult(requestCode, resultCode, data);
break;
}
}
FBLoginShareHelper.getInstance().logout();
FBLoginShareHelper.getInstance().uploadVideoToPageAsync(
"[page access token string]",
"[page id]",
[video file here],
"[Video title here]",
"[Video description here]",
new IFBLoginShareHelper.IFBVideoUploadResultCallbacks() {
@Override
public void onSuccess() {
//your code
}
@Override
public void onFail(String message) {
//your code
}
}
);