なぜこの SDK での作業が複雑なのかわかりません :(
私のアプリケーションでは、ユーザーが初めてアプリを起動したときに、トークンとユーザー ID を取得します。
public void OnFacebookLoginButtonClicked() {
// start Facebook Login
Session.openActiveSession(SplashScreen.this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(final Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
Log.i(TAG, "User name: " + user.getName() + "!, Login successfully :)");
Log.i(TAG, "User id: " + user.getId());
Log.i(TAG, "Access token is: " + session.getAccessToken());
Log.i(TAG, "Application id: " + session.getApplicationId());
SpStorage.setToken(SplashScreen.this, session.getAccessToken());
SpStorage.setFacebookUserId(SplashScreen.this, user.getId());
registerUser();
}
}
});
}
}
});
}
問題なく正常に動作します。
私のアプリケーションのどこか (フラグメント内) で、ユーザーの壁で何かを共有する必要があります。
private void shareOnFacebook() {
final Bundle params = new Bundle();
params.putByteArray("message", "Test".getBytes());
params.putByteArray("name", "American Virgin".getBytes());
params.putByteArray("link", "http://bit.ly/12345".getBytes());
params.putByteArray("description", "A Freshman College Girl on a scholarship from an ...".getBytes());
params.putByteArray("picture", "http://xxx/MOV1026.jpg".getBytes());
final Request postToWall = Request.newRestRequest(Session.getActiveSession(),
"https://graph.facebook.com/<USER_ID>/feed", params, HttpMethod.POST);
postToWall.setCallback( new Request.Callback() {
@Override
public void onCompleted(Response response) {
Log.i(TAG, response.toString());
}
});
Request.executeBatchAsync(postToWall);
}
ただし、私の応答は次のとおりです。
04-12 16:25:29.898: I/VenueFragment(29624): {応答: responseCode: 200、graphObject: null、エラー: {HttpStatus: 200、errorCode: 101、errorType: null、errorMessage: 無効なアプリケーション ID。}、 isFromCache:false}
警告はアプリケーションIDが無効であると言っているので、次のコードを試しましたが、結果は同じでした。
final Request postToWall = Request.newRestRequest(Session.getActiveSession(),
"https://graph.facebook.com/APPLICATION_ID/feed", params, HttpMethod.POST);
どう思いますか?許可だからですか?同じシナリオを説明しているウェブログをご存知でしたら、教えてください。Facebook のサンプルのすべてのコンテンツを読みましたが、それらはすべて Facebook のログイン ボタンに基づいていました。Facebookのサンプルは忘れてください。
なぜこの単純なことが私にとって複雑になっているのか、私にはわかりません :(((((