我正在使用带有PHP SDK的Facebook Graph API。
我已登录,需要所有权限(完整列表为:public class Chat extends ListActivity {
protected EditText mMessageChat;
protected Button mSendMessageBtn;
protected List<ParseObject> mMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Status");
query.orderByDescending("createdAt");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> status, ParseException e) {
mMessage = status;
MessageAdapter adapter = new MessageAdapter(getListView().getContext(), mMessage);
setListAdapter(adapter);
}
});
}
mMessageChat = (EditText) findViewById(R.id.chatMessageText);
mSendMessageBtn = (Button) findViewById(R.id.SendMessageBtn);
mSendMessageBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ParseUser currentUser = ParseUser.getCurrentUser();
String currentUserUsername = currentUser.getUsername();
String newStatus = mMessageChat.getText().toString();
if (newStatus.isEmpty()) {
AlertDialog.Builder builder = new AlertDialog.Builder(Chat.this);
builder.setMessage("Please type in a Message!");
builder.setTitle("Oops!");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
ParseObject statusObject = new ParseObject("Status");
statusObject.put("newStatus", newStatus);
statusObject.put("user", currentUserUsername);
statusObject.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(Chat.this, "Send!", Toast.LENGTH_LONG).show();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(Chat.this);
builder.setMessage(e.getMessage());
builder.setTitle("Sorry!");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
});
}
@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_chat, 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);
}
}
)。
当我使用得分API时,似乎有效(我得到了“成功”回报):email,publish_actions,user_friends,user_games_activity
但是,当我尝试检索它时:$fb->api("/me/scores",'POST', array("score" => "5"));
我得到了这个回复(和FB Graph API Explorer一样):
$fb->api("/me/scores",'GET');
{
"data": [
{
"user": {
"name": "Name_of_the_FB_account",
"id": "FB_ACCOUNT_ID"
}
}
]
}
和score
字段(documentation中指定)发生了什么?!
答案 0 :(得分:1)
刚刚发现错误是什么(虽然在imo文档中不是很清楚)。
我必须指定在GET请求中返回哪些字段。
例如:$fb->api("/me/scores?fields=score,user,application",'GET');
返回:
{
"data": [
{
"score": 5,
"user": {
"name": "Name_of_the_FB_account",
"id": "FB_ACCOUNT_ID"
},
"application": {
"category": "Games",
"link": "https://www.facebook.com/application-path/",
"name": "ApplicationName",
"namespace": "application_namespace",
"id": "APPLICATION_ID"
}
}
]
}
顺便说一下,文档中还有type
字段,显然不存在。
编辑:正如@YassineGuedidi指出的那样,这是一种正常的行为(但很明确),因为Graph API 2.4