このコードを使用して Facebook にウォール メッセージを表示していますが、DialogListeners が見つかりません。
これがアクティビティのコードです。
私はチュートリアルを使用しています: http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
public class FacebookPostMessageActivity extends Activity {
public 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 static final String APP_ID = "xxxxxxxxxxxxxxxxx";
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 postToWall(String message) {
FacebookPoster fp = new FacebookPoster();
fp.execute(message, null, null);
}
private class FacebookPoster extends AsyncTask {
protected void onPostExecute(String result) {
showToast(result);
finish();
}
@Override
protected Object doInBackground(Object... params) {
Bundle parameters = new Bundle();
parameters.putString("message", messageToPost);
parameters.putString("description", "topic share");
try {
facebook.request("me");
String response = facebook.request("me/feed", parameters, "POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") || response.equals("false")) {
return "Blank response.";
} else {
return "Message posted to your facebook wall!";
}
} catch (Exception e) {
Log.d("ShareOnFacebook", e.getMessage());
return "Failed to post to wall!";
}
}
}
public void loginAndPostToWall() {
facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}
private void showToast(String message) {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
}
これはログです。自分のアカウントを認証するためのダイアログが表示されません...直接「強制終了」が表示されます。
07-24 15:47:19.252: E/AndroidRuntime(4937): FATAL EXCEPTION: main
07-24 15:47:19.252: E/AndroidRuntime(4937): java.lang.IllegalStateException: Could not execute method of the activity
07-24 15:47:19.252: E/AndroidRuntime(4937): at android.view.View$1.onClick(View.java:2168)
07-24 15:47:19.252: E/AndroidRuntime(4937): at android.view.View.performClick(View.java:2552)
07-24 15:47:19.252: E/AndroidRuntime(4937): at android.view.View$PerformClick.run(View.java:9229)
07-24 15:47:19.252: E/AndroidRuntime(4937): at android.os.Handler.handleCallback(Handler.java:587)
07-24 15:47:19.252: E/AndroidRuntime(4937): at android.os.Handler.dispatchMessage(Handler.java:92)
07-24 15:47:19.252: E/AndroidRuntime(4937): at android.os.Looper.loop(Looper.java:130)
07-24 15:47:19.252: E/AndroidRuntime(4937): at android.app.ActivityThread.main(ActivityThread.java:3701)
07-24 15:47:19.252: E/AndroidRuntime(4937): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 15:47:19.252: E/AndroidRuntime(4937): at java.lang.reflect.Method.invoke(Method.java:507)
07-24 15:47:19.252: E/AndroidRuntime(4937): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
07-24 15:47:19.252: E/AndroidRuntime(4937): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
07-24 15:47:19.252: E/AndroidRuntime(4937): at dalvik.system.NativeStart.main(Native Method)
07-24 15:47:19.252: E/AndroidRuntime(4937): Caused by: java.lang.reflect.InvocationTargetException
07-24 15:47:19.252: E/AndroidRuntime(4937): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 15:47:19.252: E/AndroidRuntime(4937): at java.lang.reflect.Method.invoke(Method.java:507)
07-24 15:47:19.252: E/AndroidRuntime(4937): at android.view.View$1.onClick(View.java:2163)
07-24 15:47:19.252: E/AndroidRuntime(4937): ... 11 more
07-24 15:47:19.252: E/AndroidRuntime(4937): Caused by: java.lang.NoClassDefFoundError: com.facebook.android.R$drawable
07-24 15:47:19.252: E/AndroidRuntime(4937): at com.facebook.android.FbDialog.createCrossImage(FbDialog.java:106)
07-24 15:47:19.252: E/AndroidRuntime(4937): at com.facebook.android.FbDialog.onCreate(FbDialog.java:81)
07-24 15:47:19.252: E/AndroidRuntime(4937): at android.app.Dialog.dispatchOnCreate(Dialog.java:307)
07-24 15:47:19.252: E/AndroidRuntime(4937): at android.app.Dialog.show(Dialog.java:225)
07-24 15:47:19.252: E/AndroidRuntime(4937): at com.facebook.android.Facebook.dialog(Facebook.java:814)
07-24 15:47:19.252: E/AndroidRuntime(4937): at com.facebook.android.Facebook.startDialogAuth(Facebook.java:343)
07-24 15:47:19.252: E/AndroidRuntime(4937): at com.facebook.android.Facebook.authorize(Facebook.java:206)
07-24 15:47:19.252: E/AndroidRuntime(4937): at abm.face.post.FacebookPostMessageActivity.loginAndPostToWall(FacebookPostMessageActivity.java:144)
07-24 15:47:19.252: E/AndroidRuntime(4937): at abm.face.post.FacebookPostMessageActivity.share(FacebookPostMessageActivity.java:98)
07-24 15:47:19.252: E/AndroidRuntime(4937): ... 14 more
インターネット権限を持つ私のマニフェスト:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="abm.face.post" android:versionCode="1" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:name=".FacebookPostMessageActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
何か解決策をお願いします??