【发布时间】:2015-05-24 20:43:13
【问题描述】:
我正在为客户开发一个应用程序,并且我已经阅读了他(客户)在粉丝页面上发布的应用程序(Android 平台)帖子。
我创建了下面的方法,当我使用关键字 /me 运行并将输出输出到我的个人信息时,但是当我使用关键字“729745317037227/feed/”时,应用程序关闭并且什么也不返回。
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"729745317037227/feed/",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Toast.makeText(
getApplicationContext(),
response.getJSONObject()
+ "",
Toast.LENGTH_SHORT).show();
}
}
).executeAsync();
我将整个代码放在主代码中,现在我只是尝试进行查询并显示结果以供以后在片段中使用。
主类
package com.clubee.marketnow;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.HttpMethod;
import com.facebook.Profile;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
public class MainActivity extends Activity {
private TextView mainTextView;
private static final int request_code = 5;
public CallbackManager mCallbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
mCallbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_main);
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
mainTextView = (TextView) findViewById(R.id.lol);
loginButton.setReadPermissions("user_friends");
LoginManager.getInstance().logOut(); //ensures that whenever we start the app we're logged out
LoginManager.getInstance().registerCallback(mCallbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Profile curProfile = Profile.getCurrentProfile();
startNewIntent(curProfile);
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"729745317037227/feed/",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Toast.makeText(
getApplicationContext(),
response.getJSONObject()
+ "",
Toast.LENGTH_SHORT).show();
}
}
).executeAsync();
}
@Override
public void onCancel() {
// App code
mainTextView.setText("Status: Logging in cancelled");
}
@Override
public void onError(FacebookException exception) {
// App code
mainTextView.setText("Status: EXCEPTION: " + exception.toString());
}
});
}
private void startNewIntent(Profile elUsero){
Intent i = new Intent(this, RetornoFacebook.class);
i.putExtra("firstName", elUsero.getFirstName());
i.putExtra("lastName", elUsero.getLastName());
i.putExtra("picURI", elUsero.getProfilePictureUri(1500,1500).toString());
startActivityForResult(i, request_code);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onResume() {
super.onResume();
// Logs 'install' and 'app activate' App Events.
AppEventsLogger.activateApp(this);
}
@Override
protected void onPause() {
super.onPause();
// Logs 'app deactivate' App Event.
AppEventsLogger.deactivateApp(this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
if ((requestCode == request_code) && (resultCode == RESULT_OK)) {
LoginManager.getInstance().logOut();
mainTextView.setText("Status: Logged Out!");
}
}
}
谁能帮助我了解如何返回粉丝页面的提要? 我为此绞尽脑汁好几个星期,不知道我哪里出错了。我已经阅读了 100 万次 fb 文档,并且我得到的最大值是当前结果。
PS:当我在graph api explorer中做研究时,使用相同的key(729745317037227/feed/),返回成功。
很多
【问题讨论】:
-
没有人吗?我只需要了解如何将 GraphRequest 的返回设置为我的 android 活动上的字段。
标签: java android facebook facebook-graph-api mobile