我正在使用this tutorial来了解如何通过Android应用连接到Facebook。我特别感兴趣的是他展示如何在墙上发布内容/用户状态的部分。
该教程相当简单,但我的要求是我需要让应用程序附加用户发布的内容。
如何实现?
答案 0 :(得分:1)
您可以这样做:
private void publishToFacebook(String message)
{
long songId = MusicUtils.getCurrentAudioId();
long albumId = MusicUtils.getCurrentAlbumId();
String albumartUrl = MusicUtils.getArtworkUrlFromExtrasCache(getApplicationContext(),albumId);
Bitmap bm = MusicUtils.getArtworkFromExtrasCache(getApplicationContext(),albumId,false,false);
if(bm == null)
bm = MusicUtils.getDefaultArtwork(getApplicationContext());
shareFacebookConnector = new ShareConnector(MediaPlaybackActivity.this, getApplicationContext());
shareFacebookConnector.setCurrentAlbum(MusicUtils.getCurrentAlbumName());
shareFacebookConnector.setCurrentArtist(MusicUtils.getCurrentArtistName());
shareFacebookConnector.setCurrentTrack(MusicUtils.getCurrentTrackName());
shareFacebookConnector.setCurrentCoverArt(bm);
if(albumartUrl != null)
{
shareFacebookConnector.setCurrentCoverUrl(albumartUrl);
}
LayoutInflater inflater = this.getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.facebook_share, (ViewGroup) findViewById(R.id.facebook_share_root));
final ImageView image = (ImageView) dialoglayout.findViewById(R.id.facebook_cover_view);
input = (EditText) dialoglayout.findViewById(R.id.facebook_share_content);
ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.AlertDialogCustom);
AlertDialog.Builder alert = new AlertDialog.Builder(ctw);
if(message != null)
{
shareFacebookConnector.publishToFacebook(alert, input, message);
}
else
{
shareFacebookConnector.publishToFacebook(alert, input, null);
}
alert.setView(dialoglayout);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
bAlertInProgress = false;
String messageToPost = input.getText().toString();
shareFacebookConnector.postMessageToWall(messageToPost, false);
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
bAlertInProgress = false;
Toast.makeText(MediaPlaybackActivity.this, "Wall post cancelled !", Toast.LENGTH_SHORT).show();
//finish();
}
});
bAlertInProgress = true;
mShareKey = "********";
alertDialog = alert.create();
alertDialog.show();
}
答案 1 :(得分:1)
您必须以session.openForPublish();
打开会话,并且您需要权限“publish_action”