How to get FB group by alias (FQL) - facebook-fql

Does there exist any way to get group by it's alias (username)?
SELECT id, name, pic_big, type, url, username FROM profile WHERE username='somealias'
works for pages, but doesn't works for groups! For groups it returns
(#803) Some of the aliases you requested do not exist: somealias

profile table is like a parent class for user, group, page, event, or application tables. (see https://developers.facebook.com/docs/reference/fql/profile/)
It has field username but values in this field are filled from related tables, and table group has no field username (see https://developers.facebook.com/docs/reference/fql/group). So when we query profile using where id = someid we get such results:
SELECT id, name, pic_big, type, url, username FROM profile WHERE id= '195466193802264'
{
"data": [
{
"id": 195466193802264,
"name": "Facebook Developers",
"pic_big": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/groups/icon-default.png",
"type": "group",
"url": "https://www.facebook.com/groups/195466193802264/",
"username": ""
}
]
}
As you can see, username is empty for group.
update
After some investigation I found that groups CAN have usernames. Oficially they can't, but group's email part before # symbol is it's username.
When you query the profile if you only specify its username you receive nothing. But if you'll add its name your group will appear.
Example:
SELECT id, name, pic_big, type, url, username FROM profile
WHERE username = 'rock.mfc' and type = 'group'
will result
{
"data": [
]
}
But the query
SELECT id, name, pic_big, type, url, username FROM profile
WHERE name = 'ROCK MUSIC FANS CLUB' and username = 'rock.mfc' and type = 'group'
will give the required result:
{
"data": [
{
"id": 268045023346892,
"name": "ROCK MUSIC FANS CLUB",
"pic_big": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/groups/icon-guitar.png",
"type": "group",
"url": "https://www.facebook.com/groups/rock.mfc/",
"username": "rock.mfc"
}
]
}
Hope it'll help you.

Related

Retrieve UserName from ServiceNow

I am able to retrieve records for a particular Incident ID using Invoke-RestMethod. However, while retrieving the data, values like Resolved To, Updated By, etc. get populated by a sysid.
Resolved By comes in this format:
https<!>://devinstance.servicenow.com/api/sysid, value= sysid
I would like to view the username instead of the sysid.
The 'User ID' (user_name) isn't on the Incident, it's on the sys_user table, so you'll have to dot-walk to it.
If you're using the table API, you'll need to specify a dot-walked field to return, using the sysparm_fields query parameter.
This is no problem, just specify your endpoint like this:
$uri = "https://YOUR_INSTANCE.service-now.com/api/now/table/incident?sysparm_query=number%3DINC0000001&sysparm_fields=resolved_by.user_name"
I've specified a query for a specific incident number is requested, but you can replace that with whatever your query is.The important part is sysparm_fields=resolved_by.user_name. You'll want to specify any other fields you need here, as well.
The JSON I get as a result of running this API call, is the following:
{
"result": [
{
"resolved_by.user_name": "admin"
}
]
}
Note the element name: "resolved_by.user_name".
Another option for doing this, would be to tell the API to return both display, and actual values by specifying the sysparm_display_value parameter and setting it to all to return both sys_id and display value, or just true to return only display values.
Your URI would then look like this:
https://dev12567.service-now.com/api/now/table/incident?sysparm_query=resolved_byISNOTEMPTY%5Enumber%3DINC0000001&sysparm_display_value=all
And your JSON would contain the following:
"number": {
"display_value": "INC0000001",
"value": "INC0000001"
},
"resolved_by": {
"display_value": "System Administrator",
"link": "https://YOUR_INSTANCE.service-now.com/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441",
"value": "6816f79cc0a8016401c5a33be04be441"
},
"sys_updated_by": {
"display_value": "admin",
"value": "admin"
},
This would be accessed by:
answer.result[n].resolved_by.display_value

Graph API get profile image from Comment object

As the Graph API documentation says, the /comment retreives a Comment Object, which contains a from attribute, which represents the user that made the comment. By default, that from attribute comes with an id and a name.
Although I know I can get the profile image with the id, it will depend on the access_token as the way would be like this:
return 'https://graph.facebook.com/' + id + '/picture?type=large&access_token=' + accessToken;
How can I do to get the profile img of the commentator without depending on the access_token? Because when the API retreives a User object, in the fields object, you can request { fields: "id,name,picture }. But how can i do to ask for the picture to the from attribute that comes in the Comment object? As this is not allowed { fields: "id,name,from.picture }
You should be able to ask for second level attributes
https://developers.facebook.com/docs/graph-api/using-graph-api/#fieldexpansion
$ fbapi '/v2.6/me/photos?fields=from{picture}' | jq '.data[0]'
{
"from": {
"picture": "https://scontent.xx.fbcdn.net/v/t1.0-1/xxxx/p50x50/xxxx.jpg",
"id": "9999999999"
},
"id": "000000000"
}

How do I know if a Facebook Status/Photo/Link is Private?

When I'm getting a status/link/photo from facebook API, how do I know if it has been shared with the public or if it's a private post?
Also - is there a way to query only public posts?
I'm currently using the /<username>/status /<username>/links /<username>/photos endpoints.
With the graph api
From the 3 endpoints you are using, only one gives you access to the privacy settings the /<username>/links. It returns a privacy object, something like this:
{
"id": "USER_FB_ID",
"links": {
"data": [
{
"id": "ID_OF_THE_POST",
"from": {
"name": "Fábio Antunes",
"id": "USER_FB_ID"
},
"message": "Check this awesome link",
"privacy": {
"description": "Friends; Except: Restricted",
"value": "ALL_FRIENDS",
"allow": "",
"deny": "",
"networks": "",
"friends": ""
},
(etc....)
With FQL
To solve your problem you could use FQL this way you can get the 3 endpoints that have public access.
For the links you can use this query:
Select link_id,owner_comment, title, url, privacy FROM link WHERE owner = me() AND privacy.value='EVERYONE'
note: check the link table to see if there are any fields that you may want to add to this query
Since the links table from the 3 endpoints is the only with privacy settings structure to get the user photos and statuses that are public you will have to use the privacy table.
To get all the users public photos I made 2 joins, first I'm getting the user photos, then I want the privacy settings of the photos that are available to everyone and then I select the photos that have the privacy settings public:
SELECT caption,src_big FROM photo WHERE object_id IN (SELECT id FROM privacy WHERE value='EVERYONE' AND object_id IN (SELECT object_id FROM photo WHERE owner=me()))
note: check the photo table to see if there are any fields that you may want to add to this query
To get the public statuses it's the same process for the photos, two joins:
SELECT status_id , message, place_id FROM status WHERE status_id IN (SELECT id FROM privacy WHERE value='EVERYONE' AND object_id IN (SELECT status_id FROM status WHERE uid=me()))
note: check the status table to see if there are any fields that you may want to add to this query

Get List of Members of a public group from Facebook

I want to get list of ALL members of a public group using Facebook API ( preferably via FQL ). I checked https://developers.facebook.com/docs/reference/fql/ .. The table group_member does not provide such API !
Any inputs ? As this is a public group ; do we need to send any auth_access tokens ! Something like https://graph.facebook.com/fql?q=SELECT%20url,normalized_url,share_count,like_count,comment_count,total_count,commentsbox_count,comments_fbid,click_count%20FROM%20link_stat%20WHERE%20url='google.com'
works fine without any tokens..
No permissions are needed.
To read the group_member table you need:
any valid access_token if the group is public (i.e. the group's
privacy setting is OPEN)
Source: https://developers.facebook.com/docs/reference/fql/group_member/
Using Graph API
GROUP_ID/?fields=members
{
"id": "GROUP_ID",
"members": {
"data": [
{
"name": "User's name",
"administrator": false,
"id": "User's ID"
},
...
Using FQL
SELECT uid FROM group_member WHERE gid = GROUP_ID
{
"data": [
{
"uid": "100004123456789"
},
...
just follow this link https://www.facebook.com/groups/{your group id}/apps/store and add your facebook app

Fql page liked returns empty array

Im using this query and for some users it returns correct response but for some it returns empty array. I am only changing userId. Is it because of some privacy settings ?
SELECT uid FROM page_fan WHERE page_id = pageId and uid = userId
For some users it returns a good response:
{
"data": [
{
"uid": userId
}
]
}
and for some it returns a bad response like this even if they liked the page:
{
"data": [
]
}
Im using extended permissions read_stream
I updated my permissions with user_likes and uninstalled application and it works just fine.