2012-11-22 34 views
2

我是Android新手。我已經在我的應用程序中集成了Facebook,它正常工作。突然,當我想分享我的內容時,出現以上錯誤。如何解決這個請幫助我。Android Facebook錯誤。 「抱歉出現錯誤,我們正在努力盡快解決此問題」

thanxx提前

我faceboobc.java類代碼是您正在使用Facebook的對話框到Facebook在你的Android應用程序中集成...所以,有時候這會發生以下

import com.example.shareslabfb.DialogError; 
import com.example.shareslabfb.Facebook; 
import com.example.shareslabfb.Facebook.DialogListener; 
import com.example.shareslabfb.FacebookError; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.content.SharedPreferences.Editor; 
import android.os.Bundle; 

import android.view.View; 
import android.view.Window; 
import android.widget.Toast; 

public class Facebookc extends Activity{ 

    private static final String APP_ID = "............."; 
    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){ 
     /*if(!MessageList.URLToPost.isEmpty()){ 
      System.out.println("Inside IF"); 
      String title=" . For more info Click : "; 
      //facebookMessage = ""; 
      facebookMessage = MessageList.title; 
     }else{System.out.println("Inside ELSE");*/ 
     facebookMessage = ""; 


    } 
    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){ 
    Bundle parameters = new Bundle(); 
    String s; 
    if(MessageList.singleDescription.length()>70){ 
     s=MessageList.singleDescription.substring(0, 70); 
    }else{ 
     s=" "; 
    } 

    parameters.putString("title", message); 
    parameters.putString("description", s); 
    parameters.putString("picture", MessageList.imageURL); 
    parameters.putString("link", MessageList.URLToPost); 
     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(); 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    facebook.authorizeCallback(requestCode, resultCode, data); 
} 
} 

回答

相關問題