我在我的项目中进行了Facebook集成,在模拟器上一切都很好.当涉及在真实设备上运行时,它无法正常工作.我认为问题是Facebook访问令牌,我现在不知道该怎么办?所以我无法在真实设备上检索朋友信息.任何人都可以帮助我如何在真实设备上获取访问令牌.
我只使用Android SDK来获取Facebook好友信息.
mFacebook = new Facebook("api_id");
mFacebook.authorize(this, new String[] {
"publish_stream", "read_stream", "offline_access", "friends_birthday", "user_birthday", "email", "read_friendlists", "manage_friendlists"
}, this);
sToken = mFacebook.getAccessToken();
public void onComplete(Bundle values) {
Log.e("oncomplete", "value");
if (values.isEmpty()) {
Log.e("oncomplete", "value is empty");
return;
}
if (!values.containsKey("POST")) {
sToken = mFacebook.getAccessToken();
getFriends()
}
}
private void getFriends() {
try {
sToken = mFacebook.getAccessToken();
StaticUtils.sResponseId = mFacebook.request("me/friends");
Log.w("response", StaticUtils.sResponseId);
try {
JSONObject jObj = Util.parseJson(StaticUtils.sResponseId);
JSONArray jArr = jObj.getJSONArray("data");
for (int i = 0; i < jArr.length(); i++) {
JSONObject jObjFren = jArr.getJSONObject(i);
Iterator it = jObjFren.keys();
while (it.hasNext()) {
String s = (String) it.next();
// Log.w("KEY",s);
String sname = jObjFren.getString(s);
if (s.equals("id")) {
StaticUtils.sFbId.add(sname);
StaticUtils.sFbPics.add(StaticUtils.sImgUrl + sname + "/picture");
} else if (s.equals("name")) {
StaticUtils.sFbName.add(sname.toLowerCase());
}
}
}
} catch (JSONException e) {
Log.w("json exception", e.toString());
} catch (FacebookError e) {
Log.w("facebook exception", e.toString());
}
} catch (MalformedURLException e) {
Log.w("malformed exception", e.toString());
} catch (IOException e) {
Log.w("io exception", e.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢,Ammu
Tar*_*uni 11
上面给出的代码绝对正确...问题是如果我们已经在我们的设备中安装了任何facebook应用程序,升级版本比我们使用我们的应用程序将无法工作...如果我们在我们的设备中卸载facebook应用程序它将工作...还有另一种方法来通过以下步骤在我们的设备中处理我们的应用程序和其他facebook应用程序:::如果你使用eclipse然后转到
Windows>首选项> Android>构建并获取调试密钥库的路径
现在打开终端并运行以下命令
keytool -export -alias androiddebugkey -keystore"debug keystore path"| openssl sha1 -binary | openssl enc -a -e
它将要求输入密码然后输入android作为你的密码现在将HASH KEY添加到位于@ http://www.facebook.com/developers/的 Facebook API配置 下的EDIT SETTINGS/Mobile and Devices屏幕下.
现在我能够在HTC设备上运行我的应用程序
| 归档时间: |
|
| 查看次数: |
6424 次 |
| 最近记录: |