话不多说,直接上代码了
// 邀请好友
public void sendFilteredChallenge(final Vector<String> vectFilerFirends, final String strMsg)
{
// Get a list of the user's friends' names and devices
final Session session = Session.getActiveSession();
Request friendDevicesGraphPathRequest = Request.newGraphPathRequest(
session, "me/friends", new Request.Callback()
{
@Override
public void onCompleted(Response response)
{
// Hide the progressContainer now that the network call
// has completed
FacebookRequestError error = response.getError();
if (error != null)
{
} else if (session == Session.getActiveSession())
{
if (response != null)
{
// Get the result
GraphObject graphObject = response
.getGraphObject();
JSONArray dataArray = (JSONArray) graphObject
.getProperty("data");
// [{"id":"100000439770527","name":"Yujia Xu"},{"id":"100000504584571","devices":[{"os":"Android"},{"os":"iOS","hardware":"iPhone"}],"name":"Hu Rong"},{"id":"100001195425864","devices":[{"os":"Android"}],"name":"Wu Junzi"},{"id":"100003790094643","name":"Kun Qiu"}]
if (dataArray.length() > 0)
{
ArrayList<String> filteredFriendIDs = new ArrayList<String>();
for (int i = 0; i < dataArray.length(); i++)
{
JSONObject currentUser = dataArray
.optJSONObject(i);
if (currentUser != null)
{
String strId = currentUser.optString("id");
boolean bFlag = false;
for(int j=0; j<vectFilerFirends.size(); j++)
{
if(strId.equalsIgnoreCase(vectFilerFirends.get(j)))
{
bFlag = true;
break;
}
}
if(!bFlag)
{
filteredFriendIDs.add(currentUser.optString("id"));
}
}
}
Bundle params = new Bundle();
params.putString("message",strMsg);
params.putString(
"suggestions",
TextUtils
.join(",",
filteredFriendIDs
.toArray(new String[filteredFriendIDs
.size()])));
// Show FBDialog without a notification bar
showDialogWithoutNotificationBar(
"apprequests", params);
}
}
}
}
});
// Pass in the fields as extra parameters, then execute the Request
Bundle extraParamsBundle = new Bundle();
extraParamsBundle.putString("fields", "name,devices");
friendDevicesGraphPathRequest.setParameters(extraParamsBundle);
Request.executeBatchAsync(friendDevicesGraphPathRequest);
}
private void showDialogWithoutNotificationBar(String action, Bundle params)
{
// Create the dialog
WebDialog dialog = new WebDialog.Builder(mstaticContext,
Session.getActiveSession(), action, params)
.setOnCompleteListener(new WebDialog.OnCompleteListener()
{
@Override
public void onComplete(Bundle values,
FacebookException error)
{
//[{to[0]=100000504584571, request=612136952185524}]
if (error != null
&& !(error instanceof FacebookOperationCanceledException))
{
// (mstaticContext).showError(mstaticContext.getResources().getString(R.string.network_error),
// false);
}
else
{
if(values != null)
{
String strRquestId = (String) values.getCharSequence("request");
Vector<String> vectString = new Vector<String>();
int nCount = 0;
for(int i=0; i<200; i++)
{
String strKey = "to["+i+"]";
String strValue = values.getString(strKey);
if(strValue != null &&!strValue.equalsIgnoreCase(""))
{
vectString.add(strValue);
nCount++;
}
}
mfacebookCallback.sendRuquestCallback(vectString, strRquestId);
}
}
}
}).build();
// Hide the notification bar and resize to full screen
Window dialog_window = dialog.getWindow();
dialog_window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Show the dialog
dialog.show();
}