- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我已经成功地创建了一个发布在我的 facebook 墙上的类(class)。但是我该如何更改代码以在我的 Facebook 粉丝专页上分享呢?我在 google 或 stack overflow 上找不到任何东西...
这是在 facebook 上分享的类:
package com.celticwolf.blahblah; <--- changed
import com.facebook.android.*;
import com.facebook.android.Facebook.DialogListener;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Toast;
public class ShareOnFacebook extends Activity{
private static final String APP_ID = "35255389027859"; <--- changed
private static final String[] PERMISSIONS = new String[] {"publish_stream"};
private static final String TOKEN = "access_token";
private static final String EXPIRES = "expires_in";
private static final String KEY = "facebook-credentials";
private Facebook facebook;
private String messageToPost;
public boolean saveCredentials(Facebook facebook) {
Editor editor = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
editor.putString(TOKEN, facebook.getAccessToken());
editor.putLong(EXPIRES, facebook.getAccessExpires());
return editor.commit();
}
public boolean restoreCredentials(Facebook facebook) {
SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE);
facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
return facebook.isSessionValid();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
facebook = new Facebook(APP_ID);
restoreCredentials(facebook);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.facebook_dialog);
String facebookMessage = getIntent().getStringExtra("facebookMessage");
if (facebookMessage == null){
facebookMessage = "Test wall post";
}
messageToPost = facebookMessage;
}
public void doNotShare(View button){
finish();
}
public void share(View button){
if (! facebook.isSessionValid()) {
loginAndPostToWall();
}
else {
postToWall(messageToPost);
}
}
public void loginAndPostToWall(){
facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}
public void postToWall(String message){
new MyAsyncTask().execute(message);
}
class MyAsyncTask extends AsyncTask<String,Void,Boolean>
{
public Boolean doInBackground(String ...message){
Bundle parameters = new Bundle();
parameters.putString("message", message[0]);
parameters.putString("description", "topic share");
try {
facebook.request("me");
String response = facebook.request("me/feed", parameters, "POST"); <--- I think here is the crucial part
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
return Boolean.FALSE;
}
else {
return Boolean.TRUE;
}
} catch (Exception e) {
e.printStackTrace();
return Boolean.FALSE;
}
}
public void onPostExecute(Boolean result){
if(result == Boolean.TRUE){
showToast("posted successfully");
}else{
showToast("couldn't post to FB.");
}
finish();
}
}
class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {
saveCredentials(facebook);
if (messageToPost != null){
postToWall(messageToPost);
}
}
public void onFacebookError(FacebookError error) {
showToast("Authentication with Facebook failed!");
finish();
}
public void onError(DialogError error) {
showToast("Authentication with Facebook failed!");
finish();
}
public void onCancel() {
showToast("Authentication with Facebook cancelled!");
finish();
}
}
private void showToast(String message){
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
}
谢谢!
最佳答案
<罢工>
<罢工>String response = facebook.request("me/feed", parameters, "POST");
<罢工>
me/feed
变成 PAGE_ID/feed
:
String response = facebook.request("PAGE_ID/feed", parameters, "POST");
在此处了解如何使用图谱 API:https://developers.facebook.com/docs/reference/api/
关于java - 通过应用程序在 Facebook 粉丝页面上发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14186642/
我的网站上有一个 Faceboon 粉丝 api,我想自己设置它的样式,但我似乎没有用。我确实将 CSS 设置为 ftp 上的 css 文件,但它就像风扇盒一样使用了它。 谁知道问题出在哪里? 风扇盒
我有一个博客 (wordpress) 和一个用于我博客的 facebook 粉丝页面(拥有超过 1 个粉丝!)。每次我在我的博客上发布内容时,我都想在我的 FB 墙上发布一条消息。最好是 PHP。 同
我在我的博客上使用官方粉丝框小部件有一段时间了,想用加载更少内容的缓存版本的小部件替换它。 小部件(适用于 Wordpress)运行良好 (http://www.electriceasel.com/p
我一直在尝试从我的一个业务页面中删除所有大约 5 万的关注者。我使用 Selenium Web 驱动程序和 Python 来废弃。 我能够获得关注者对话框,并且我能够滚动该对话框以加载更多关注者。然而
我是一名优秀的程序员,十分优秀!