在入门Android的FB图形API空响应 [英] Getting null response in android fb graph api
本文介绍了在入门Android的FB图形API空响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试使用 FB图形API
但效应初探
我得到的 空
当我尝试在我的Android应用程序抓取网页的帖子。
我试图让页面从一个ID我用一页纸。
我期望得到含饲料的图形响应。
但我得到了一个空响应
。
公共类FB扩展活动{按钮fbbt1;
CallbackManager callbackManager;AccessTokenTracker accessTokenTracker;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_fb); 尝试{ FacebookSdk.sdkInitialize(getApplicationContext()); fbbt1 =(按钮)findViewById(R.id.fbbutton);
callbackManager = CallbackManager.Factory.create(); LoginManager.getInstance()。registerCallback(callbackManager,
新FacebookCallback< LoginResult>(){
@覆盖
公共无效的onSuccess(LoginResult loginResult){
//应用code
} @覆盖
公共无效onCancel(){
//应用code
// savedInstanceState
} @覆盖
公共无效onerror的(FacebookException除外){
//应用code
Toast.makeText(fb.this,exception.toString(),Toast.LENGTH_LONG).show();
}
});
LoginManager.getInstance()logInWithReadPermissions(此,Arrays.asList(public_profile,user_groups))。 accessTokenTracker =新AccessTokenTracker(){
@覆盖
保护无效onCurrentAccessTokenChanged(
的accessToken oldAccessToken,
的accessToken currentAccessToken){ }
}; fbbt1.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
尝试{
getUserData(AccessToken.getCurrentAccessToken());
Toast.makeText(fb.this,访问令牌。+ AccessToken.getCurrentAccessToken()为gettoken()的toString(),Toast.LENGTH_LONG).show();
}
赶上(例外五){
Toast.makeText(fb.this,错误是:+ e.toString(),Toast.LENGTH_LONG).show();
} }
});
}
赶上(例外五){
Toast.makeText(fb.this,e.toString(),Toast.LENGTH_LONG).show();
}
}
公共无效getUserData(的accessToken的accessToken){ GraphRequest.newGraphPathRequest(
的accessToken,/ 415004402015833 /帖,
新GraphRequest.Callback(){
@覆盖
公共无效onCompleted(GraphResponse graphResponse){
尝试{
Toast.makeText(fb.this对象长度是:+ graphResponse.getJSONObject()长(),Toast.LENGTH_LONG。).show();
Toast.makeText(fb.this,要求是:+ graphResponse.getRequest(),Toast.LENGTH_LONG).show();
字符串RESP = graphResponse.getRawResponse();
Toast.makeText(fb.this的回应是:+ RESP,Toast.LENGTH_LONG).show();
}赶上(例外五){
Toast.makeText(fb.this,错误是:+ e.toString(),Toast.LENGTH_LONG).show();
}
}
})executeAsync()。
} @覆盖
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
super.onActivityResult(要求code,结果code,数据);
callbackManager.onActivityResult(要求code,结果code,数据);
} @覆盖
保护无效的onDestroy(){
super.onDestroy();
尝试{
accessTokenTracker.stopTracking();}
赶上(例外五){
Toast.makeText(fb.this,错误是:+ e.toString(),Toast.LENGTH_LONG).show();
}
}
}
一组解决方案
我曾误用的ID,而不是一个页面。但现在,我把它改成415004402015833(页面的ID)。现在,职位来了。
感谢您的帮助......
I have been trying to use fb graph api
but the reponse
i am getting is null
when i try to fetch the posts of a page in my android application.
I am trying to get the page feeds from a page whose ID i have used.
I expect to get a graph response containing the feeds.
But i got a null response
.
public class fb extends Activity {
Button fbbt1;
CallbackManager callbackManager;
AccessTokenTracker accessTokenTracker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fb);
try {
FacebookSdk.sdkInitialize(getApplicationContext());
fbbt1 = (Button) findViewById(R.id.fbbutton);
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
}
@Override
public void onCancel() {
// App code
// savedInstanceState
}
@Override
public void onError(FacebookException exception) {
// App code
Toast.makeText(fb.this, exception.toString(), Toast.LENGTH_LONG).show();
}
});
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile, user_groups"));
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
}
};
fbbt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
getUserData(AccessToken.getCurrentAccessToken());
Toast.makeText(fb.this, "Access Token: "+ AccessToken.getCurrentAccessToken().getToken().toString(), Toast.LENGTH_LONG).show();
}
catch (Exception e){
Toast.makeText(fb.this, "error is: "+e.toString(), Toast.LENGTH_LONG).show();
}
}
});
}
catch (Exception e){
Toast.makeText(fb.this, e.toString(), Toast.LENGTH_LONG).show();
}
}
public void getUserData(AccessToken accessToken){
GraphRequest.newGraphPathRequest(
accessToken, "/ 415004402015833/posts",
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
try {
Toast.makeText(fb.this, "Object Length is : " + graphResponse.getJSONObject().length(), Toast.LENGTH_LONG).show();
Toast.makeText(fb.this, "request was: " + graphResponse.getRequest(), Toast.LENGTH_LONG).show();
String resp = graphResponse.getRawResponse();
Toast.makeText(fb.this, "response is: " + resp, Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(fb.this, "error is: " + e.toString(), Toast.LENGTH_LONG).show();
}
}
}).executeAsync();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onDestroy() {
super.onDestroy();
try{
accessTokenTracker.stopTracking();}
catch (Exception e){
Toast.makeText(fb.this, "error is: "+e.toString(), Toast.LENGTH_LONG).show();
}
}
}
解决方案
I had wrongly used id of a group rather than a page. But now, i have changed it to 415004402015833 (id of a page). Now, the posts are coming. Thanks for help....
这篇关于在入门Android的FB图形API空响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文