0
我已經與Facebook Android SDK中這些時間的實驗......Android的Facebook應用程序interupt的Facebook SDK
順便說一句,我使用Facebook到Android集成的教程,在彈出的對話框佈局... 鏈接http://integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
這個代碼,我使用:
public class Sharefb extends Activity {
private static final String APP_ID = "xxxxxxxxxxxxxxxx";
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.main);
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, new LoginDialogListener());
}
public void postToWall(String message){
Bundle parameters = new Bundle();
parameters.putString("message", message);
facebook.dialog(this, "stream.publish", parameters, new WallPostDialogListener());
}
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();
}
}
class WallPostDialogListener implements DialogListener {
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
showToast("Message posted to your facebook wall!");
} else {
showToast("Wall post cancelled!");
}
finish();
}
public void onFacebookError(FacebookError e) {
showToast("Failed to post to wall!");
e.printStackTrace();
finish();
}
public void onError(DialogError e) {
showToast("Failed to post to wall!");
e.printStackTrace();
finish();
}
public void onCancel() {
showToast("Wall post cancelled!");
finish();
}
}
private void showToast(String message){
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
}
不幸的是,每一次我做的請求......窗口只是閃爍幾秒鐘,然後完成...
後來,當我刪除我的模擬器上的Facebook應用程序,它工作正常,我可以發佈新消息在我的牆上...
有什麼不對嗎? 我希望你們大家很快會發現
坦克你!
你們中的一些人可能有窗口覆蓋或其某種類型的問題...,但這不是問題!我已經通過刪除我的清單上的theme.dialog使佈局獨立,並且仍然無法發佈我的消息,直到我刪除我的模擬器上的Facebook應用程序... – user724861 2011-04-26 06:54:46
我不確定,但請檢查此鏈接:http:// stackoverflow .COM /問題/ 5786442/Android的Facebook的共享問題上的設備 – Farhan 2011-04-26 07:03:26