在我的应用程序中,我收到邮件时遇到问题,
我的代码,
private void getFbName() {
mProgress.setMessage("Fetching data ...");
mProgress.show();
new Thread() {
@Override
public void run() {
String name = "";
String email = "";
String firstname = "";
String lastname = "";
String gender = "";
int what = 1;
try {
String me = mFacebook.request("me");
JSONObject jsonObj = (JSONObject) new JSONTokener(me)
.nextValue();
System.out.println(jsonObj);
name = jsonObj.getString("name");
email = jsonObj.getString("email");
firstname = jsonObj.getString("first_name");
lastname = jsonObj.getString("last_name");
gender = jsonObj.getString("gender");
what = 0;
name = name + "~" + email+"~"+firstname+"~"+lastname+"~"+gender;
} catch (Exception ex) {
ex.printStackTrace();
Log.e(LOG_TAG, ex.getMessage());
}
mFbHandler.sendMessage(mFbHandler.obtainMessage(what, name));
}
}.start();
}
/** The m fb handler. */
private Handler mFbHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
mProgress.dismiss();
if (msg.what == 0) {
String username = (String) msg.obj;
username = (username.equals("")) ? "No Name" : username;
SessionStore.saveName(username, getApplicationContext());
String[] cre = username.toString().split("~");
if (cre != null) {
String fbname = cre[0];
String fbemail = cre[1];
String fbfirstname = cre[2];
String fblastname = cre[3];
String fbgender = cre[4];
Toast.makeText(getApplicationContext(),
fbname+fbemail+fbfirstname+fblastname+fbgender, Toast.LENGTH_SHORT).show();
Utilities.setUserRole("1");
Intent i = new Intent(
getBaseContext(),
com.petapp.fragment.ItemListActivity.class);
startActivity(i);
}
} else {
Toast.makeText(getApplicationContext(),
"Connected to Facebook", Toast.LENGTH_SHORT).show();
}
}
};
我的 json 回复
{"work":[{"employer":{"id":"108225245912126","name":"globas"}}],"hometown":{"id":"105868576120246","name":"Coimbatore, Tamil Nadu"},"location":{"id":"105868576120246","name":"Coimbatore, Tamil Nadu"},"locale":"en_US","link":"http:\/\/www.facebook.com\/peter.das.395","education":[{"type":"College","school":{"id":"115034085174725","name":"CSICE KETTI"}}],"updated_time":"2013-05-24T08:24:55+0000","id":"100005889543373","first_name":"Peter","timezone":5.5,"username":"peter.das.395","verified":true,"name":"Peter Das","last_name":"Das","gender":"male"}
我的日志猫说,
W/System.err(9081): org.json.JSONException: No value for email
W/System.err(9081): at org.json.JSONObject.get(JSONObject.java:354)
W/System.err(9081): at org.json.JSONObject.getString(JSONObject.java:510)
W/System.err(9081): at com.petapp.demographic.LoginActivity$8.run(LoginActivity.java:263)
E/LoginActivity(9081): No value for email
但同时我使用不同的 facebook 凭证我会得到邮件 id 我不知道这里发生了什么??请帮助任何人....