アプリケーションをソーシャル ネットワーク (facebook と twitter) と統合しようとしています。
たとえば、ユーザー ウォールまたはパブリック ウォールにアクセスして、スクロール ビューやアイテム ビュー (または任意の提案!!!) のようにレイアウトに投稿したいのですが、これは Twitter で解決されますが、できません。その作品をフェイスブックに載せます。
グラフ API を使用します。
ウォールに投稿するには、メソッドpostTextOnMyWallを作成します。
public String postTextOnMyWall(String message) {
Log.d("Tests", "Testing graph API wall post");
try {
Bundle parameters = new Bundle();
parameters.putString("message", message);// key/value
this.mAsyncRunner.request("me/feed", parameters, "POST",
new WallPostTextRequestListener(), null);
} catch (Exception e) {
e.printStackTrace();
}
return message;
}
public AsyncFacebookRunner getmAsyncRunner() {
return this.mAsyncRunner;
}
public void setmAsyncRunner(AsyncFacebookRunner mAsyncRunner) {
this.mAsyncRunner = mAsyncRunner;
}
}
テキスト メッセージを投稿するためのリスナーとしてのこのメソッド、WallPostTextRequestListener
public class WallPostTextRequestListener implements RequestListener {
public void showToast(String message) {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT)
.show();
}
// called on successful completion of the Request
@Override
public void onComplete(String response, Object state) {
Log.d("WallPostTextRequestListener", "Got response: " + response);
String message = "<empty>";
try {
JSONObject json = Util.parseJson(response);
message = json.getString("message");
showToast("Mensagem escrita no teu mural facebook!: " + message);
} catch (JSONException e) {
Log.e("WallPostTextRequestListener", "JSON Error in response");
} catch (FacebookError e) {
Log.e("WallPostTextRequestListener",
"Facebook Error: " + e.getMessage());
}
final String text = "Mensagem: " + message;
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
// TODO Auto-generated method stub
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
// TODO Auto-generated method stub
}
// called if there is an error
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
}
そして、Facebookログインのオブジェクトを使用して、onClickボタンで投稿するだけです
// this is the editext where i write my post
String messageFace = ((EditText) findViewById(R.id.message))
.getText().toString();
lf.postTextOnMyWall(messageFace);
自分のウォールまたは公開ページからフィードを取得するにはどうすればよいですか? 前もって感謝します!