我已經構建了一個活動,使用this實現(請參閱接受的答案)在用戶的Facebook牆上發佈狀態更新。當Facebook應用安裝在設備/模擬器上時發佈到用戶的Facebook牆不工作
如果模擬器/手機沒有安裝facebook應用程序,它沒問題。
如果模擬器/手機安裝了Facebook應用程序,Facebook應用程序會加載登錄屏幕,但嘗試登錄後,Facebook應用程序會消失,並將我帶回到我的應用程序。
有沒有人有facebook應用程序安裝時的這種經歷?
我的代碼:
public class AchievementActivity extends Activity implements DialogListener, OnClickListener{
private Facebook facebook;
Button facebookPostButton;
String defaultFacebookPost;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.achievements);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_layout);
View achievementDivider = (View)findViewById(R.id.achievementDivider);
int[] colors = {0, 0xff00ffff, 0};
achievementDivider.setBackgroundDrawable(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
//get the title of the achievement from the intent that started this activity from the activity StatisticsActivity
String achievementTitleString = getIntent().getStringExtra("title");
String achievementTextToDisplay = getAchievementTextToDisplay(achievementTitleString);
defaultFacebookPost = getDefaultPost(achievementTitleString);
//ImageView achievementActivityAchievementBadgeImageView = (ImageView)findViewById(R.id.achievementActivityAchievementBadgeImageView);
TextView achievementActivityBadgeTitleTextView = (TextView)findViewById(R.id.achievementActivityBadgeTitleTextView);
achievementActivityBadgeTitleTextView.setText(achievementTitleString);
TextView achievementActivityAchievementText = (TextView)findViewById(R.id.achievementActivityAchievementText);
achievementActivityAchievementText.setText(achievementTextToDisplay);
facebookPostButton = (Button)findViewById(R.id.facebookPostButton);
facebookPostButton.setOnClickListener(this);
}
@Override
public void onComplete(Bundle values) {
if (values.isEmpty())
{
Toast.makeText(getApplicationContext(), "Empty", Toast.LENGTH_SHORT);
return;
}
if (!values.containsKey("post_id"))
{
try
{
Bundle parameters = new Bundle();
parameters.putString("message", defaultFacebookPost);// the message to post to the wall
facebook.dialog(AchievementActivity.this, "stream.publish", parameters, this);// "stream.publish" is an API call
}
catch (Exception e)
{
// TODO: handle exception
System.out.println(e.getMessage());
}
}
try
{
facebook.logout(getApplicationContext());
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onFacebookError(FacebookError error)
{
Toast.makeText(AchievementActivity.this, "onFacebookError", Toast.LENGTH_LONG);
}
@Override
public void onError(DialogError e)
{
Toast.makeText(AchievementActivity.this, "onError", Toast.LENGTH_LONG);
}
@Override
public void onCancel()
{
Toast.makeText(AchievementActivity.this, "onCancel", Toast.LENGTH_LONG);
}
@Override
public void onClick(View v)
{
if (v == facebookPostButton)
{
facebook = new Facebook("my_facebook_api");
// replace APP_API_ID with your own
facebook.authorize(this, new String[] {"publish_stream", "read_stream", "offline_access"}, this);
}
}
private String getDefaultPost(String defaultTitleString)
{
//do some stuff here to get a string to post to wall
return defaultPost;
}
private String getAchievementTextToDisplay(String achievementTitleString) {
String achievementTextToDisplay = "DEFAULT";
//do some stuff here to get text to display in the activity
//this has nothing to do with the facebook post...
return achievementTextToDisplay;
}
}
logcat的告訴我:
05-11 13:03:34.076: INFO/ActivityManager(98): Starting activity: Intent { cmp=com.facebook.katana/.ProxyAuth (has extras) }
05-11 13:03:34.246: INFO/ActivityManager(98): Displayed activity com.facebook.katana/.ProxyAuth: 158 ms (total 158 ms)
05-11 13:03:35.166: DEBUG/dalvikvm(12390): GC_FOR_MALLOC freed 6729 objects/418424 bytes in 44ms
05-11 13:03:35.166: DEBUG/webviewglue(12390): nativeDestroy view: 0x527e20
05-11 13:03:35.166: DEBUG/NativeCrypto(12390): Freeing OpenSSL session
編輯 :必須在過去一年多臺計算機安裝了Android開發平臺和總是有後在創建新的開發環境之後,Facebook遇到了一個問題,我發現這個簡單的答案可能是Facebook實現在一個設備上工作而不是另一個設備上的原因...
對於您使用不同證書打包的每個應用程序版本,祕密Facebook API密鑰(您在developer.facebook.com上列出的密鑰)將會有所不同。例如,假設你有兩臺開發機器。由於這兩臺機器都將使用不同的證書構建應用程序,因此您必須確保爲每臺機器生成Facebook API密鑰並將其列在developer.facebook.com上。
您是否安裝了最新的FB應用更新?當我過去使用FB SDK時,我遇到了一些麻煩,導致FB應用程序未更新到最新版本(檢查市場應用程序,我的應用程序,確保FB應用程序沒有可用的更新)。 – 2011-05-12 06:48:17
@Mathias Lin - 我使用的是FaceDook SKD附帶的Facebook版本。當你從gitHub獲取應用程序時,他們給你一個應用程序的編譯副本。 – dell116 2011-05-13 15:57:05