我尝试从 facebook.com 接收好友请求,但出现异常
W/System.err(1139):com.facebook.android.FacebookError:无效的 OAuth 访问令牌。W/System.err(1139):在 com.facebook.android.Util.parseJson(Util.java:279) W/System.err(1139):在 test.project.facebook.AutFacebookActivity$1$2.onComplete(AutFacebookActivity. java:147) W/System.err(1139):at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:254)
我的java代码:
private void authorize(){
intent = new Intent(AutFacebookActivity.this,FaceListView.class);
fb.authorize(this,new DialogListener(){
@Override
public void onComplete(Bundle values){
Toast.makeText(AutFacebookActivity.this,"Вы вошли",Toast.LENGTH_LONG).show();
asyncRanFace.request("me/friends",new RequestListener(){
public void onComplete(String response, Object state) {
try{
JSONObject json = Util.parseJson(response);
JSONArray friendsArray = json.getJSONArray("data");
//friendsList = new ArrayList<HashMap>();
String fId,fNm;
JSONObject friend;
for(int i =0 ; i<friendsArray.length(); i++){
friend = friendsArray.getJSONObject(i);
fId = friend.getString("id");
fNm= friend.getString("name");
myFriendsMap.put(fId, fNm);
}
intent.putExtra("map1",myFriendsMap);
}catch(JSONException e){
e.printStackTrace();
}
catch(FacebookError e){
e.printStackTrace();
}
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
@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
}
});
asyncRanFace.request("me/friendrequests?access_token=read_requests",new RequestListener(){
public void onComplete(String res, Object state) {
try{
JSONObject jsonRequest = Util.parseJson(res);
JSONArray friendsRequestArray = jsonRequest.getJSONArray("data");
JSONObject friendRequest;
String fRId,fRNm;
for(int i =0 ; i<friendsRequestArray.length(); i++){
friendRequest= friendsRequestArray.getJSONObject(i);
fRId = friendRequest.getString("id");
fRNm= friendRequest.getString("name");
myRequestFriendsMap.put(fRId, fRNm);
intent.putExtra("map2",myRequestFriendsMap);
startActivity(intent);
}
}catch(JSONException e){
e.printStackTrace();
}
catch(FacebookError e){
e.printStackTrace();
}
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
@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
}
});
}
@Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
@Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
Toast.makeText(AutFacebookActivity.this, "Вы вышли", Toast.LENGTH_LONG).show();
}
});
}