Is it possible to get a Facebook user's name from their Facebook Id number with a graph call?
If so, does anyone know the call?
For example you can get a user's picture by making the following call
"http://graph.facebook.com/" + someUserId + "/picture"
Something like:
String response = facebook.request(userId);
JSONObject json = Util.parseJson(response);
String name = json.getString("name");
String username = json.getString("username");
Simply querying the Graph API with the user_id should be enough to get the name of the user -
http://graph.facebook.com/4
>>
{
"id": "4",
"name": "Mark Zuckerberg",
"first_name": "Mark",
"last_name": "Zuckerberg",
"link": "https://www.facebook.com/zuck",
"username": "zuck",
"gender": "male",
"locale": "en_US",
"updated_time": "2012-05-20T01:29:18+0000",
"type": "user"
}
You could drill down even more by adding a filter for the name field -
https://graph.facebook.com/4?fields=name
>>
{
"name": "Mark Zuckerberg",
"id": "4",
"type": "user"
}
https://graph.facebook.com/UserID.
eg:
https://graph.facebook.com/19292868552
Related
I am trying to consume below record using JSON with Volley, but it is not a JSONArray, How can I change it to use it in :
JsonArrayRequest movieReq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
Mean while, The URL in the record seems not correct. How to remove extar forward slashes from url or I can use it to fetch the JPG image?
{
"ID": "131",
"Lead": "",
"Title": "\u06f2\u06f0 \u06af\u0644 \u0641\u0648\u0642 \u0627\u0644\u0639\u0627\u062f\u0647 \u0631\u0648\u0646\u0627\u0644\u062f\u0648 \u062f\u0631 \u0644\u06cc\u06af \u0642\u0647\u0631\u0645\u0627\u0646\u0627\u0646",
"ContentTime": "09:56",
"TypeContent": "public",
"PTime": "1395\/05\/09 - 11:47",
"Content": " <\/div>",
"Tags": "\u0641\u0648\u062a\u0628\u0627\u0644#\u0631\u0648\u0646\u0627\u0644\u062f\u0648#\u0648\u0631\u0632\u0634\u06cc#######",
"Price": "0",
"GID": "106",
"GTitle": "\u0648\u0631\u0632\u0634\u06cc",
"PicURL": "http:\/\/video.dmedia.ir\/images\/news\/131\/thumb_131.jpg",
"comment_count": "0",
"view_count": "0",
"Media": [{
"GID": "359",
"GType": "mp4",
"Title": "",
"URL": "http:\/\/video.dmedia.ir\/images\/news\/131\/media\/359.mp4",
"ADV": 0
}],
"smscontent": null,
"Rels": [{
"RelID": "130",
"RelTitle": " \u0645\u0647\u062f\u0648\u06cc: \u062f\u0648\u0633\u062a \u062f\u0627\u0631\u0645 \u0648\u0627\u0644\u06cc\u0628\u0627\u0644\u0645 \u0628\u0627 \u06cc\u06a9 \u062e\u0627\u0637\u0631\u0647 \u062e\u0648\u0628 \u062a\u0645\u0648\u0645 \u0634\u0648\u062f"
}],
"Comments": []
}
Solution:
We can make JSON object request and JSON array request:
I found this helpful.
http://www.androidhive.info/2014/09/android-json-parsing-using-volley/
hi there is one plugin Gson for android studio.You need to install.Then go to CTRL + insert.
You can create gson file.
Enter some name for java file.
Click that file then Paste you json data. Click ok.
You can see your created json to gson format.
thanks hope this will help you.
create model class for this data then use follwing code
ModelClass class=new GSON.fromJSON("your Data ", ModelClass.class )
Hi I am new to Android and i am developing one app in which i will send request to server and get json data.The problem is that when receive response fron server and when i trying to get that i get one exception
java.lang.String cannot converted to JSONobject
Your server returned incorrect json-data. There are extra " that should be removed.
It should look similar to
[{
"image": "http://eprintpost.com/images/savepreflab/uploadSave/69120e7d-31e0-46ac-bf07-e86778bc2866.jpg",
"productid": "255",
"oldprice": "250",
"city": "Pune",
"price": "200",
"labname": "Emotions",
"productname": "Sublimation Bag (6058)"
}, {
"image": "http://eprintpost.com/images/savepreflab/uploadSave/48e9420c-3bd2-4c89-91a3-0de3346c072f.jpg",
"productid": "481",
"oldprice": "1000",
"city": "Coimbatore",
"price": "500",
"labname": "savithri photo house",
"productname": "camera toploader 450AW Black"
}, {
"image": "http://eprintpost.com/images/savepreflab/uploadSave/741e6549-94be-439d-b823-0bd8b26bb0ce.jpg",
"productid": "556",
"oldprice": "1000",
"city": "Dharwad",
"price": "400",
"labname": "Foto Magic Studio And Lab",
"productname": "07.jpg"
}]
Could you put all your error log cat ? Where is exactly throw this error
type java.lang.String cannot be converted to JSONObject
Your error is parsing from String to JSONObject so let focus on which lines make a parsing to JSONObject
I have a ListView that is using a custom adapter to populate its rows.
I want to get two String values from the adapter that I have clicked, so I used getItem method:
#Override
public UserItemsModel getItem(int i) {
return arrUserItems.get(i);
}
As you can see above, I'm suing UserItemsModel as a reference to get the item id.
So, in the list fragment, I retrieve the values I desired by using onListItemClicked method:
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
UserItemsModel userItemsModel = (UserItemsModel) l.getAdapter().getItem(position);
String item_id = userItemsModel.getItem_id();
//String user_id = userItemsModel.getUser_id(); This is not in the UserItemsModel
mListener.onUserItemSelected(user_id, item_id);
}
However, the user_id is not in the UserItemsModel (as I have modeled from a Json format), instead user_id is in the other model that the adapter doesn't use.
UserItemsModel look like this:
public class UserItemsModel {
private String item_id; // i can get this
private String item_name;
No user_id that I wanted. But, it is in UserShopModel which is a parent of UserItemsModel
public class UserShopModel {
private String user_id; // i can't get this
private String username;
private String name;
When I run the app, it throws an error that says something like Cannot Cast UserShopModel into UserItemsModel
Anyone know how to get around this? If anything unclear please let me know.
UDPATE:
Here is how the JSON look like:
{
"results": {
"user_id": "2947",
"username": "100001235797881",
"name": "Fast Reload",
"email": "atiqahfatin76#yahoo.com",
"phone": "6Lparw1NrMmpu7gd2U18mg==",
"avatar": "http:\/\/ked.ai\/uploads\/avatar\/2947_avatar.png",
"shop_name": "FastReload",
"shop_desc": "our vision is to provide Fast And Easy reload service in malaysia. After One time registeration You can top up anytime anywhere at any number with lower price using sms system.24\/7, no internet connection required. Click here http:\/\/www.fastreload.tk\/ For more info and registeration .Thank You =)",
"shop_namespace": "FastReload",
"shop_canvas": "http:\/\/ked.ai\/uploads\/canvas\/2947_canvas.png",
"profile": [
{
"id": "1",
"title": "Shop Name",
"content": "FastReload"
},
{
"id": "2",
"title": "Shop Namespace",
"content": "FastReload"
},
{
"id": "3",
"title": "Shop Description",
"content": "our vision is to provide Fast And Easy reload service in malaysia. After One time registeration You can top up anytime anywhere at any number with lower price using sms system.24\/7, no internet connection required. Click here http:\/\/www.fastreload.tk\/ For more info and registeration .Thank You =)"
},
{
"id": "4",
"title": "Customer Service",
"content": "operation hours 9 am to 9 pm"
},
{
"id": "5",
"title": "Trust Level",
"content": "0%"
},
{
"id": "6",
"title": "Bank Details",
"content": null
}
],
"items": [
{
"item_id": "20321",
"name": "Fast And Easy Reload Service",
"price": "20",
"description": " our vision is to provide Fast And Easy reload service in malaysia. After One time registeration You can top up anytime anywhere at any number with lower price using sms system.24\/7, no internet connection required.Click here http:\/\/www.fastreload.tk\/ For more info and registeration .Thank You =)",
"category_id": "127",
"category": "Services",
"vanity": [
],
"thumbnail": {
"image50": "http:\/\/ked.ai\/uploads\/item\/100001235797881\/2947_1391259043.71a8deec82a92fc51acfa63c7a87c263_50.jpg",
"image100": "http:\/\/ked.ai\/uploads\/item\/100001235797881\/2947_1391259043.71a8deec82a92fc51acfa63c7a87c263_100.jpg"
}
}
],
"vanities": [
],
"categories": [
{
"category_id": "127",
"category_name": "Services",
"category_url": "http:\/\/ked.ai\/FastReload\/category\/services",
"count": "1"
}
]
},
"errors": ""
}
If you wish to obtain the user id from the ShopModel, then the only way you might want to do this, is:
1. Either pass the userShopModel as an argument to the constructor of the adapter.
The assumption you might want to make is, UserShopModel and UserItemModel
have the same number of items(that is the size is the same)
2. The other thing you could do is, inside every userItemModel create a property
of the type UserShopModel such that for every item that you click,
you not only get the item_id but also the user_id
Hope this helps.
I trying to get my immediate family data from facebook using FQL. I run this statement:
SELECT first_name, middle_name, last_name, birthday_date
from user
where uid IN (SELECT uid
FROM family
WHERE profile_id = me()
and (relationship = 'brother'
or relationship = 'sister'
or relationship = 'father'
or relationship = 'mother'
or relationship = 'son'
or relationship = 'daughter'
or relationship = 'wife'
or relationship = 'husband'))
But I want to have also the relatioship in the data. It gives me only first_name, middle_name, last_name, birthday_date
You have to do a to get this data, you need to do an FQL multi-query:
{"my_family": "SELECT uid, relationship FROM family WHERE profile_id = me() AND
(relationship = 'brother' OR ...)".
"family_details": "SELECT first_name, middle_name, last_name, birthday_date FROM
user WHERE uid IN (SELECT uid FROM #my_family)"}
You'll need to join the two result objects together on uid in your script.
Do you need to use FQL? There is now a nested field Graph API syntax that gets you exactly what you need in one go:
https://graph.facebook.com/me?fields=id,name,family.fields(first_name,middle_name,last_name,birthday)
The result is then a nested JSON object with the relationship field as you require - something like:
{
"id": "738229837",
"name": "James Pearce",
"family": {
"data": [
{
"first_name": "Bob",
"last_name": "Pearce",
"birthday": "09/21/1965",
"id": "12345",
"relationship": "cousin"
},
{
"first_name": "Clara",
"last_name": "Pearce",
"birthday": "12/08",
"id": "67890",
"relationship": "mother"
}
...
],
"paging": {
"next": "https://graph.facebook.com/..."
}
}
}
Hope that helps. Have fun.
I am having a few problems getting Facebook data to parse properly.
I am working on implementing part of an application to allow a user to select and use one of their own facebook photos within the app. I have gotten the facebook login/logout code working and I am currently getting the token (once logged in) in order to gather the users Album information. The permission set is also working nicely, however I am now stuck at trying to get the JSON information to parse correctly. Here is a sample snippet of the information I need to parse:
"data": [
{
"id": "3486732467234",
"from": {
"name": "Persons Name",
"id": "Persons ID"
},
"name": "Vacation",
"location": "City",
"link": "https://www.facebook.com/album.php?fbid=434235&id=324343&aid=2430",
"cover_photo": "3489234432",
"privacy": "everyone",
"count": 60,
"type": "normal",
"created_time": "2007-06-03T23:01:16+0000",
"updated_time": "2011-03-18T19:46:43+0000",
"can_upload": true
},
{
"id": "4043544665",
"from": {
"name": "Persons Name",
"id": "Persons ID"
},
"name": "Vacation 2",
"location": "City",
"link": "https://www.facebook.com/album.php?fbid=4043434665&id=508154335&aid=2555",
"cover_photo": "5434543",
"privacy": "everyone",
"count": 60,
"type": "normal",
"created_time": "2007-06-03T22:53:03+0000",
"updated_time": "2011-03-18T19:45:55+0000",
"can_upload": true
}],
...more paging JSON information ...}}
I need to be able to pull the album information in order to display the photo album names in a list (and use the ID in another query). Once I can get the albums to show, I would then use those IDs to perform another query to get the photos from that album. Again I can also get that information back, I am just not sure how to properly parse it.
Any useful tips that someone might have in being able to parse this into a listview would be greatly appreciated.
I need to target pulling the first ID and the Album name ("id": "3486732467234" and "name": "Vacation" from the first listing)
why don't you try with the json classes...
something like this:
jsonObject = new JSONObject(your_data);
jArray = jsonObject.getJSONArray("data");
for(int i =0;i<jArray.length();i++){
String name= jArray.getJSONObject(i).getString("name");
String location= jArray.getJSONObject(i).getString("location");
etc.
The new Android Facebook SDK 3.0 returns a Response object in the Response.Callback() listener when making Graph API calls. This response object can be used to create a GraphObject which can be used to get a JSON...ex:
Request graphRequest = Request.newGraphPathRequest(session, graphRequestString, new Request.Callback() {
#Override
public void onCompleted(Response response) {
//Create the GraphObject from the response
GraphObject responseGraphObject = response.getGraphObject();
//Create the JSON object
JSONObject json = responseGraphObject.getInnerJSONObject();
}
});