0
我是android.I中的新人我想通過我的應用程序實現Facebook的牆貼。我已經做了其他方面,但牆上帖子沒有正確完成。當我點擊textview然後我的應用程序顯示應用stopped..please幫助我..通過Android應用程序在facebook上的feed文章
上稱爲點擊類..
public void Share(View view)
{
Intent share =new Intent(this, SharePerks.class);
//use.putExtra("perk_name", perk_name);
//use.putExtra("perk_short_desc", perk_short_desc);
//use.putExtra("perk_summary_desc", perk_summary_desc);
startActivity(share);
}
SharePerks.class
public class SharePerks extends FragmentActivity{
private Button ShareButton;
private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback =
new Session.StatusCallback() {
@Override
public void call(Session session,
SessionState state, Exception exception) {
onSessionStateChanged(session, state, exception);
}
};
boolean SharePerksWhenSessionOpened;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.hide();
setContentView(R.layout.share);
/*ShareButton = (Button) findViewById(R.id.Share_btn);
ShareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//onClickPickFriends();
if (ensureOpenSession()) {
publishFeedDialog();
}
else {
SharePerksWhenSessionOpened = true;
}
/*}
});*/
Log.e("on create", "inside on create");
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
// ensureOpenSession();
}
@Override
protected void onResume() {
super.onResume();
uiHelper.onResume();
AppEventsLogger.activateApp(this);
Log.e("on resume", "in onresume method");
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
private boolean ensureOpenSession()
{
if (Session.getActiveSession() != null || Session.getActiveSession().isOpened())
{
Session.openActiveSession(SharePerks.this, true, new Session.StatusCallback()
{
@Override
public void call(Session session, SessionState state, Exception exception)
{
onSessionStateChanged(session, state, exception);
}
});
return false;
}
return true;
}
private void onSessionStateChanged(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
SharePerksWhenSessionOpened = false;
publishFeedDialog();
}
}
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(SharePerks.this,
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(SharePerks.this,
"Perk Shared",
Toast.LENGTH_SHORT).show();
finish();
} else {
// User clicked the Cancel button
Toast.makeText(getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
finish();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
finish();
} else {
// Generic, ex: network error
Toast.makeText(getApplicationContext(),
"Error posting story",
Toast.LENGTH_SHORT).show();
finish();
}
}
})
.build();
feedDialog.show();
}
}