[英]using facebook SDK in android , How to invite friend?
這是第一次在android中使用facebook SDK,所以在使用facebook登錄我的應用程序之后! 我檢索了我的invitable_friends並在listView中顯示它們
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/invitable_friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
try {
JSONObject object = new JSONObject(response.getRawResponse());
JSONArray array = object.getJSONArray("data");
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
String id = jsonObject.optString("id");
String name = jsonObject.optString("name");
String url = jsonObject.optJSONObject("picture").optJSONObject("data").optString("url");
Person person = new Person(id,name,url);
person.setId(id);
person.setName(name);
person.setUrl(url);
list.add(person);
}
} catch (JSONException e) {
e.printStackTrace();
}
listView.setAdapter(new FriendsAdapter(getApplicationContext(),list));
現在,我需要向我的朋友發送邀請,以便在點擊時使用我的應用程序。
所以我在OnItemClickListener上處理它
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String appLinkUrl;
appLinkUrl = "Application Link";
if (AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(appLinkUrl)
.build();
AppInviteDialog.show(FriendsList.this, content);
}
}
});
}
}
).executeAsync();
我跟蹤流程的成功或失敗
appInviteDialog = new AppInviteDialog(this);
appInviteDialog.registerCallback(callbackManager, new FacebookCallback<AppInviteDialog.Result>() {
@Override
public void onSuccess(AppInviteDialog.Result result) {
Log.d("Yehia","onSuccess result = "+ result.getData().toString());
}
@Override
public void onCancel() {}
@Override
public void onError(FacebookException e) {
Log.d("Yehia","onError message = "+ e.getMessage());
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
但很遺憾總是onError被叫! 我知道我有一些誤解。 有誰能夠幫助我 ! 注意:我的鏈接應用程序尚未運行! 提前致謝 。
實際上,當我將它切換到v4.0.0時,我正在使用SDK v4.11.0。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.