get the mutual friends in facebook API Android application - java

Hy guys, i am try to get the mutual friends between the logged user and other users by belwo method but i got empty data node although the error is null. any help regarding this issue.
private void getMutualFriends() {
Bundle params = new Bundle();
params.putString("fields", "id,name,picture");
getFriendsIds().put("100005132166273", "");
RequestBatch requestBatch = new RequestBatch();
for (final String friendId : getFriendsIds().keySet()) {
requestBatch.add(new Request(Session.getActiveSession(), "/me/mutualfriends/" + friendId, params, HttpMethod.GET, new Request.Callback() {
public void onCompleted(Response response) {
Log.i("Result: " , response.toString());
GraphObject graphObject = response.getGraphObject();
if (graphObject != null) {
if (graphObject.getProperty("id") != null) {
}
}
}
}));
}
requestBatch.executeAsync();
}
I always got this response {Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache:false}.
I replace the request creation by this also "new Request(Session.getActiveSession(), "me/mutualfriends/" + friendId, null, HttpMethod.GET, new Request.Callback().......
And got the same response.
I will execute the method about 1000 time so i used Facebook request batch if you know better method lets me know please.

I know I might be a bit naive here, but maybe the users you're checking have no mutual friends?
Are you familiar with the "Graph API" explorer? It's very useful:
https://developers.facebook.com/tools/explorer/
Try pasting your url (remember to replace 'friendsId' with the user you're checking against) and see what you get.

Related

Facebook Graph Request for user friends is returning an empty array

So I am developing an app that uses the FacebookSDK. When I try to request the user's friends however, I receive an empty array. I know that you can only access friends who have also approved you app/permissions (And I did allow the access to friends list for both people that have used the app). There are two users on my app, myself and a test user, but for whatever reason the JSONArray is empty in the Graph request response. Does anybody know what is going wrong? Here is my code:
AccessToken fbAccessToken = AccessToken.getCurrentAccessToken();
GraphRequest userFBFriendsGraphRequest = GraphRequest.newMyFriendsRequest(fbAccessToken, new GraphRequest.GraphJSONArrayCallback() {
#Override
public void onCompleted(JSONArray returnedObjArr, GraphResponse response) {
Log.e("JSONArray", "The completed json array is " + returnedObjArr);
}
});
Bundle requestParameter = new Bundle();
requestParameter.putString("fields", "id, name, picture");
userFBFriendsGraphRequest.setParameters(requestParameter);
userFBFriendsGraphRequest.executeAsync();
Thank you for the help ahead of time.

JSON of 10 posts from wp json rest api v1 For Android App

from a wordpress site, using json rest api, we get the json of the whole site. I want to load the json of first 10 posts from all category for android. I am using volley to load the json array and it is failing to load the whole array response as it is huge is size. I want first 10 posts and when I click load more I want the json of 11th post to 20th post. can I do so?
currently my url is like http://www.example.com/wp-json/posts
I am requesting in following code
JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET,
baseUrl,
(String) null,
new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
Log.d("json",response.toString());
listRecentPost = parseJsonResponse(response);
Log.d("LSN", listRecentPost.isEmpty() + "");
// If any data is avialable
if (!listRecentPost.isEmpty()) {
postAdapter.setRecentPost(listRecentPost);
postAdapter.notifyDataSetChanged();
/*
suppose data connection is off so error image and text will show
* but when my connection will be okk then i need to disable this image and error text
* */
errorImage.setVisibility(View.GONE);
errorMsg.setVisibility(View.GONE);
}
else {
errorMsg.setVisibility(View.VISIBLE);
errorMsg.setText("No Post Available");
}
//disable loading icon
swipeRefreshLayout.setRefreshing(false);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d("LSN", error.toString() + "VolleyError");
// enable error iamge and text
errorImage.setVisibility(View.VISIBLE);
errorMsg.setVisibility(View.VISIBLE);
if (error instanceof TimeoutError || error instanceof NoConnectionError) {
errorMsg.setText(error.toString());
} else if (error instanceof AuthFailureError) {
errorMsg.setText(error.toString());
} else if (error instanceof ServerError) {
errorMsg.setText(error.toString());
} else if (error instanceof NetworkError) {
errorMsg.setText(error.toString());
} else if (error instanceof ParseError) {
errorMsg.setText(error.toString());
}
//again try to load data after 30 seconds
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
swapeRefresh();
}
}, 30000);
}
});
Currently I got an exception like com.android.volley.TimeoutError
And What the parameter requestBody does in JsonArrayRequest ? why we use null here?
explaining with codes will be better for me.
Thanks in advance.
Why do we use null there?
Because your request is using the HTTP-Method "Get" which passes Arguments via URL. If you use HTTP-Method "Post" you would put your request data into that JSONObject so volley can append that to HTTP-Body-Data.
you could try setting a custom RetryPolicy, since Volley timeouts after 4 seconds of waiting for repsponse - see here
Pinning down the exact problem is kinda hard with the provided information. I cant see a problem with your Request itself.
Shot in the blue:
Argument 3 (String) null, maybe pass in an empty json object.
I would definitely try to investigate deeper into volley by setting it to verbose via adb:
adb -s shell setprop log.tag.Volley VERBOSE
that way volley provides further debug information in your LogCat.
Good Luck

How to send verification code back to my application from Parse Cloud after success?

So I'm building a signup procedure that needs the user to verify their phone number by receiving a code by sms. I'm using Parse as the backend system and I'm using Twilio service which comes included in Parse to take care of the sms function. I have been successful in sending the verification code to user's number.
This is my parse cloud code:
var client = require('twilio')('ACb3....', '2b3....');
//Send an SMS text message
Parse.Cloud.define("sendVerificationCode", function(request, response) {
var verificationCode = Math.floor(Math.random()*999999);
client.sendSms({
From: "+61437877758",
To: request.params.phoneNumber,
Body: "Your verification code is " + verificationCode + "."
}, function(err, responseData) {
if (err) {
response.error(err);
} else {
response.success("Success");
}
});
});
This is the code from the app:
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("phoneNumber", userNumber);
ParseCloud.callFunctionInBackground("sendVerificationCode", params, new FunctionCallback<String>() {
public void done(String result, ParseException e) {
if (e == null) {
Log.d("Parse", result);
Intent i = new Intent(SignupActivity.this, PhoneVerificationActivity.class);
startActivity(i);
} else {
Toast.makeText(SignupActivity.this, "there was a problem with connection", Toast.LENGTH_LONG).show();
}
}
});
Now I would like to know how can I send that verification code back to my android app from Parse Cloud after success, so tat I can check the verification code against the code user puts in the EditText
if (err) {
response.error(err);
} else {
*//So the code for sending the verification code back goes here:*
response.success("Success");
}
Do I need to use Json and Rest API?, how can I call and grab this verification code from the app?.
I would really appreciate your help. Thanks.
One way would be to return it in response.success...
response.success({ status: "success", verificationCode: ... });
Another way, a better way, is to not trust the client with this. Store a record of it on an object on the server... When the user enters the validation code, call back into another function to check if it is valid. An example of this type of system can be seen in this old out-dated GitHub login example: https://github.com/ParsePlatform/CloudCodeOAuthGitHubTutorial/blob/master/cloud/main.js#L116

How to Share media file on Twitter using gigya on Android

I am facing problems in sharing media file using Gigya on Twitter. Please look below at the code snippet.
It is giving a error code as 0 but on the post, only text is getting posted.
private void share(){
GSObject userAction = new GSObject();
userAction.put("title", "Text");
GSArray mediaItems = new GSArray();
try {
mediaItems.add(new GSObject("{\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}"));
userAction.put("mediaItems", mediaItems);
} catch (Exception e) {
e.printStackTrace();
}
GSObject params = new GSObject();
params.put("userAction", userAction);
params.put("enabledProviders", "twitter");
GSAPI.getInstance().sendRequest("socialize.publishUserAction", params, new GSResponseListener() {
#Override
public void onGSResponse(String method, GSResponse response, Object context) {
if (response.getErrorCode() == 0) {
Log.d( "Twitter Auth Token","Session token Response Error ");
} else {
Log.d( "Twitter Auth Token","Session token Response Error "+response);
}
}
}, null);
}
Gigya does not support uploading and sharing an image within a tweet. The recommended approach would be to include a link to the image within the tweet itself.
Hope this helps
EDIT
I don't think there is a solution for this issue.
Please look in Gigya documentation and examples:
1. Share.
2. Advance share.
Answer bellow is incorrect.
End EDIT
It seems that you may be missing the 'type' in the mediaItems object.
Please look in Gigya documentation.
The output user action json should look like this:
{
'title' : 'text',
'mediaItems' : [{
'type' : 'image',
'src' : 'http://www.f2h.co.il/logo.jpg',
}
],
}

HttpPost and HttpRequest multiple responses

I have a Http Post
try {
String response1 = null;
response1 = CustomHttpClient.executeHttpPost(
"http://giveaway.synamegames.com/appfiles/login.php",
postParameters);
String res = response1.toString();
// res = res.trim();
res = res.replaceAll("\\s+", "");
if (res.equals("2350") && checkboxv.equals("1")) {
Intent login = new Intent(this, MainMenuActivity.class);
login.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(login);
SavePreferences("lu", et_username.getText().toString());
SavePreferences("lp", et_pass.getText().toString());
SavePreferences("cbauto", "1");
} else if (res.equals("2350") && checkboxv.equals("0")) {
Intent login = new Intent(this, MainMenuActivity.class);
login.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(login);
SavePreferences("lu", "");
SavePreferences("lp", "");
SavePreferences("cbauto", "0");
} else if (res.equals("1000")) {
Toast.makeText(this, "Incorrect version. Please update.",
Toast.LENGTH_SHORT).show();
} else if (res.equals("588")) {
Toast.makeText(this, "Incorrect Password or Username.",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this,
"Server Error. Please try again later.",
Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
}
If my response is 1000, 2350, etc. it'll give the android phone a specific response. However I want my database to give android database information. In my situation I have
players register and enter in their name, email, username, and password. Upon login I want the phone to retrieve the name the user assigned when they created their account. For security reasons I can't store this information on the phone. I could have multiple HTTP Posts but that would just slow the application down. My question is...
Is there any possible way I can retrieve multiple responses and put those responses into different Strings without having to do another http post?
If you are designing the server side also, what I would do is basically returning the profile information as part of the response in JSON format. You could use JSONObject from Android to parse the JSON response from your server. So your response String for successful login would look like
{
"response" : {
"responseCode" : 2350,
"userProfile" : {
"name" : "Me",
"email" : "me#me.com"
}
}
}
And for failed response
{
"response" : {
"responseCode" : 588
}
}
This way, you don't have to make 2 http calls and would save you from another trip to the server

Categories