发布使用Android的Facebook的API文本状态 - 最简单的方法 [英] Posting a Text Status using Facebook API in Android - The simplest method
本文介绍了发布使用Android的Facebook的API文本状态 - 最简单的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在寻找了很多找到一个方法来做到这一点。但似乎没有为我工作。可有人请在做这方面的帮助?
I have been searching a lot to find a way to do this. But nothing seems to be working for me. Can someone please help in doing this?
这是我的Facebook状态后的图像按钮:
This is my image button for facebook status post:
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/hoributtons"
android:layout_alignTop="@+id/imageButton2"
android:background="#00000000"
android:contentDescription="@string/facebook"
android:onClick="shareOnFacebook"
android:src="@drawable/facebookbutton" />
这是我的mainactivity.java文件的相应部分:
This is my mainactivity.java file's corresponding part:
public class MainActivity extends FacebookActivity {
private static final String APP_ID = "xxxxxxxxxxxxx";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void shareOnFacebook(View v) {
//mfacebook = new Facebook("xxxxxxxxxxxxx");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
在正确的方向可有人点? :)
Can someone point in the right direction? :)
推荐答案
假设你想发布你自己的墙壁(因为这个问题不明确),这应该为你工作。
Assuming that you want to post on your own wall (since the question is not clear), this should work for you.
public class MainActivity extends Activity {
private static final String APP_ID = "xxxxxxxxxxxxx";
private Facebook mFacebook;
private AsyncFacebookRunner mAsyncRunner;
private EditText yourEditText;
private String toShare;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mFacebook = new Facebook();
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
SessionEvents.addAuthListener(new SampleAuthListener());
SessionEvents.addLogoutListener(new SampleLogoutListener());
yourEditText = (EditText) findViewById(R.id.<youreditTextId>);
toShare = yourEditText.getText().toString();
}
public void shareOnFacebook(View v) {
Bundle params = new Bundle();
params.putString("message", toShare);
mAsyncRunner.request("me/feed", params, "POST", new RequestListener() {
public void onMalformedURLException(MalformedURLException e) {}
public void onIOException(IOException e) {}
public void onFileNotFoundException(FileNotFoundException e) {}
public void onFacebookError(FacebookError e) {}
public void onComplete(String response) {
}
});
Toast.makeText(MainActivity.this, "Posting to your Wall", Toast.LENGTH_SHORT).show();
}
}
有关的图片张贴到墙上细节, Facebook的具有良好的文档。
For details on posting pictures to wall, Facebook has a good documentation.
这篇关于发布使用Android的Facebook的API文本状态 - 最简单的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文