Facebook API: How to get count of group members - facebook

Im working on fb app using PHP client and FQL.Looks like that fb api doesnt support this. You can get max random 500 members with FQL. But when group has more than 500 members there is no way how to get total count of members.
I need only number dont care about member details.
Anyone can help me please?

I have actually found that you cannot, it is by design apparently. I wanted to know this myself about a month ago, and found that no matter what parameters you pass in to the graph api, you can not get past the 500th member. Even if you tell it to start at number 450 and give you 200, it will give you only 450-500.
Here's me asking, and the unfortunate answer:
http://forum.developers.facebook.net/viewtopic.php?id=82134

you can use graph api 2.0 and sdk 4.0
you can use below code
$url1= "https://graph.facebook.com/".$gid."/members?limit=10000&access_token=".$_SESSION['fb_token'];
if(!extension_loaded('curl') && !#dl('curl_php5.so'))
{
return "";
}
$parsedUrl = parse_url($url1);
$ch = curl_init();
$options = array(
CURLOPT_URL => $url1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => array("Host: " . $parsedUrl['host']),
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => false
);
curl_setopt_array($ch, $options);
$response_count = #curl_exec($ch);
$json_count = json_decode($response_count);
foreach ($json_count as $item_count)
{
$cnt=count($item_count);
break;
}

You can use the summary parameter which will return a total_count value.
/v2.11/{GROUP_ID}?fields=members.limit(0).summary(true)
It also works when searching for groups:
/v2.11/search?q=stackoverflow&type=group&fields=id,name,members.limit(0).summary(true)
{
"data": [
{
"id": "667082816766625",
"name": "Web Development Insiders",
"members": {
"data": [
],
"summary": {
"total_count": 2087
}
}
},
{
"id": "319262381492750",
"name": "WEB Developers India",
"members": {
"data": [
],
"summary": {
"total_count": 10240
}
}
}...
]
}

Make a query to:
https://graph.facebook.com/v2.11/{group-id}/members?limit=1500&access_token={token}
(replace {group-id} by the numeric group identification and {token} by your access token).
You will get a response like this:
{
"data": [
{
"name": "Foo bar",
"id": "123456",
"administrator": false
},
...
],
"paging": {
"cursors": {
"before": "QVFIUkwzT3FKY0JSS2hENU1NUlZAocm9GelJMcUE3S1cxWWZAPYWx1cUQxcXFHQUNGLUJnWnZAHa0tIdmpMT0U5ZAjRBLUY5Q2ZAGbmwwVTNoSHhLc1BCc2dvVTF3",
"after": "QVFIUkFoU3lYR2tXc09adkg5OGhlbHRWRk1GYkZAzQU1DalRSY05zOVl5aE1tcjRMS3lXLURaVWNMOGZArWTVxS2hPQUVGVWxhbXZAyZA0p3azVKM2hBSEp3YlpR"
}
},
"next": "https://graph.facebook.com/v2.11/123928391023981/members?access_token=EAACEdEose0cBALBDrdgLyVOjzW4mz6G3d3Yj1fTGYqygVgYq0JCDZAi0zYsY90pSSQ9hQZCn3TdwfXIAiyoXH5oUYcA4hOcCI9jztkkUhbBv9tEQ3ZBEEuHpmkm3kmgvk1HNq5mo6BM0hz8XkOLVh3twIdz83KhB9SkqxuxHeFD9GWsQqjys6XTuL2315QZD&pretty=0&limit= 1500&after=QVFIUkFoU3lYR2tXc08adkg5OGhlbHRWYk1GYkZAzQU1DalRSY05zOVl5aQ1tcjRMS3lXLURaVWNMOGZArWTVxS2hPQUVGVWxhbXZAyZA0p3azVKM1hBSEp3YlpR"
}
Then follow this algorithm:
Make a count variable with a 0 value.
Count the objects in the data array of the latest response and add the count to the count variable.
If the latest response has the next property, make a request to the URL which is the next property value and return to the step 2. Otherwise you have finished, the count of members is the count variable value.
This way is not very good because the more members there are in the group the more queries are required. I would be better to parse the number of members from the group page HTML but I can't find reliable way to do it.
Update 2017.10.19: If the Facebook API response size is more then about 345KB, Facebook returns an error: Please reduce the amount of data you're asking for, then retry your request. It is about 1997 members. So you need to set the limit request parameter to 1500 not to face the error.
Update 2018.01.26: There is a way to get a count of members using a single request: https://stackoverflow.com/a/47783306/1118709
Update 2018.01.31: After 90 days from releasing Graph API v2.12 the request will require an access token of an admin of the group. Source: Graph API docs / v2.12 changelog / 90-day breaking changes

You should do it with an FQL query on the group_member table like:
SELECT uid FROM group_member WHERE gid = <group_id> limit 500 offset 500
Example here: Is it possible / how to get number of a particular Facebook Group members (even if number of them is 500+)?

Related

Keycloak RestAPI: Assign client role to group

I have trying this:
url="https://{localhost}/auth/admin/realms/{realm_name}/groups/{group_id}/role-mappings"
payload=[{"id":"role_id","name":"Role_name","composite":"false","clientRole":"true","containerId":"client_id"}]
But, it doesnt work, i think it may be related to the wrong payload
Any ideas pls
We can use the python-keycloak lib: https://pypi.org/project/python-keycloak/
there is a function: assign_group_client_roles
The format is correct but you make sure the client has available payloaded role.
This is example for, "Hr" group added "RomoteApp" client the "tile limit" role.
In Keycloak UI, # Client > RemoteApp > Roles
Role name
time limit
Groups > hr
Client Roles: RemoteApp
Available Roles: time limit
Assigned Roles: not yet include "time limit"
POST commend by Postman - I am not yet can attache image due to low level of stan overflow
http://127.0.0.1:8080/auth/admin/realms/Test-realm/groups/9efef6bf-7edb-496e-bc0d-a8d4f5f4e3a9/role-mappings/clients/60a19179-f244-42f8-9950-04f2119a4e5b?client=RemoteApp&id=60a19179-f244-42f8-9950-04f2119a4e5b&realm=Test-realm
in body of postman with row JSON option ( Content-Type : application/json )
[
{
"id": "e17f9f7f-62dc-4998-b058-49b845ff5cef",
"name": "time limit",
"description": "time limit",
"composite": false,
"clientRole": true,
"containerId": "60a19179-f244-42f8-9950-04f2119a4e5b"
}
]
group list
{
"id": "9efef6bf-7edb-496e-bc0d-a8d4f5f4e3a9",
"name": "hr",
"path": "/hr",
"subGroups": []
}
client list
{
"id": "60a19179-f244-42f8-9950-04f2119a4e5b",
"clientId": "RemoteApp",
...
}
also don't remember the access token called by token endpoint w/ grant_type is password
http://127.0.0.1:8080/auth/realms/Test-realm/protocol/openid-connect/token

How to get code coverage percentage for latest build from TFS 2017u2 using PowerShell & REST API

Using PowerShell, how can I query Team Foundation Server 2017 Update 2 (on-premises) to get the code coverage percentage metric from the latest completed gated check-in?
I've not found a clear API call to use in the MS reference documentation. In the web interface, I can see in the dashboard for a given completed build the percentage value and a link to download the entire Visual Studio coverage file. I don't want the file, though. I just want to make an API call and get the percent coverage value for the last successful build of a given definition.
Unfortunately, the docs for VSTS's REST API are down right now, but this should get you started (pulled from Google's Cache).
This endpoint handles everything related to Tests and Code Coverage.
https://{instance}/DefaultCollection/{project}/_apis/test/codeCoverage?api-version={version}[&buildId={int}&flags={int}]
Provide values for the following and then run this Invoke-RestMethod to get the data back.
$Instance = 'fabrikam-fiber-inc.visualstudio.com' #your URL here
$ProjectName = #YourProjectNameHere
$buildID = #YourBuildIDHere
$version = '2.0-preview'
Invoke-RestMethod -uri https://$Instance/DefaultCollection/$ProjectName/_apis/test/codeCoverage?api-version=$version
Here's a sample response you can get back:
Status code: 200
{
"value": [
{
"configuration": {
"id": 51,
"flavor": "Debug",
"platform": "Any CPU",
"uri": "vstfs:///Build/Build/363",
"project": {}
},
"state": "0",
"lastError": "",
"modules": [
{
"blockCount": 2,
"blockData": "Aw==",
"name": "fabrikamunittests.dll",
"signature": "c27c5315-b4ec-3748-9751-2a20280c37d5",
"signatureAge": 1,
"statistics": {
"blocksCovered": 2,
"linesCovered": 4
},
"functions": []
}
],
"codeCoverageFileUrl": "..."
}
],
"count": 1
}
It looks like blocksCovered and livesCovered are probably the closest you'll get from the API. Let me know if you need some help or get stuck. Eventually, the docs will be back online at this URL.

Facebook GraphAPI and FQL API return different value for same URL

I trying to migrate my facebook app from FQL API (1.0) to GraphAPI (2.3) and i encounter some problems.
Main goal of my facebook application is fetching current count of likes, shares and comments for specified links (article url). (I think, something similar to How to get facebook share, like, comment count for a url with graph api only (in a non-deprecated way))
In (old) FQL API i could get this information by executing SELECT ... FROM link_stat table. ex.:
https://graph.facebook.com/fql?access_token=xxxxxxxxxxxx|yyyyyyyya&q=SELECT%20click_count%2Ccomment_count%2Ccommentsbox_count%2Clike_count%2Cshare_count%2Ctotal_count%2Cnormalized_url%20FROM%20link_stat%20WHERE%20url%20IN%20%28"http%3A//sport.wp.pl/kat%2C1715%2Ctitle%2CSwiat-pokochal-polskiego-sportowca-Mimo-ze-ledwo-dukal-po-angielsku%2Cwid%2C17449498%2Cwiadomosc.html"%29
which return information in JSON, ex.:
{
"data": [
{
"like_count": 21,
"comment_count": 0,
"click_count": 0,
"commentsbox_count": 0,
"total_count": 29,
"share_count": 8,
"normalized_url": "http://sport.wp.pl/kat,1715,title,Swiat-pokochal-polskiego-sportowca-Mimo-ze-ledwo-dukal-po-angielsku,wid,17449498,wiadomosc.html"
}
]
}
In new GraphAPI (2.3) theoretically this information is available via:
URL and /{object-id}/likes edges:
https://developers.facebook.com/docs/graph-api/reference/v2.3/url
https://developers.facebook.com/docs/graph-api/reference/v2.0/object/likes
Which return value. ex.:
{
"share": {
"comment_count": 0,
"share_count": 42
},
"og_object": {
"url": "http://sport.wp.pl/kat,1715,title,Swiat-pokochal-polskiego-sportowca-Mimo-ze-ledwo-dukal-po-angielsku,wid,17449498,wiadomosc.html",
"description": "Kibice wstrzymali oddech, dos\u0142ownie. W sali s\u0142ycha\u0107 by\u0142o tykaj\u0105c\u0105 wskaz\u00f3wk\u0119 zegara zawieszonego na \u015bcianie. Przy stole sta\u0142 Bogdan Wo\u0142kowski, nieruchomo patrzy\u0142 na \u015brodek, gdzie znajdowa\u0142a si\u0119 wysoka piramida z\u0142o\u017cona z kilku poziom\u00f3w bil i tr\u00f3jk\u0105t\u00f3w. Na jej szczycie sta\u0142 cz\u0142owiek. Mija\u0142y kolejne sekundy, napi\u0119cie ros\u0142o. Nagle \"Wizard\" wzi\u0105\u0142 kij do r\u0119ki, przymierzy\u0142, hukn\u0105\u0142 w bil\u0119, ta uderzy\u0142a w piramid\u0119 i...",
"type": "article",
"title": "\u015awiat pokocha\u0142 polskiego sportowca. Mimo \u017ce ledwo duka\u0142 po angielsku",
"updated_time": "2015-04-14T19:46:03+0000",
"id": "1055320127830544"
},
"id": "http://sport.wp.pl/kat,1715,title,Swiat-pokochal-polskiego-sportowca-Mimo-ze-ledwo-dukal-po-angielsku,wid,17449498,wiadomosc.html"
}
and
{
"1055320127830544": {
"data": [],
"summary": {
"total_count": 0
}
}
}
Unfortunately this values isn't consistent with results from FQL API .
So, my question is:
What mean each value in response, and why it is not consistent with FQL?
It seems to be a known issue with the API. You can follow this post for updates.
This post has a good explanation of how to get share counts.
Also what I have noticed is that for API version 2.1 and above, share_count in the response contains the total number of shares including the link shared directly on the Timeline by the user. For version 2.0, I think shares in the response excludes this.

How to get list of podcast episodes from an album (iTunes Search API)

I'm trying to obtain the list of podcasts episodes from the iTunes Search API. I'm able to make a call to the API and get back all podcast albums based on a search term:
https://itunes.apple.com/search?media=podcast&term=nerdcast
This returns the following json (cropped):
{
"resultCount": 20,
"results": [
{
"wrapperType": "track",
"kind": "podcast",
"collectionId": 381816509,
"trackId": 381816509,
"artistName": "Nerdcast",
"collectionName": "Nerdcast",
"trackName": "Nerdcast",
"collectionCensoredName": "Nerdcast",
"trackCensoredName": "Nerdcast",
"collectionViewUrl": "https://itunes.apple.com/us/podcast/nerdcast/id381816509?mt=2&uo=4",
"feedUrl": "http://jovemnerd.com.br/categoria/nerdcast/feed/",
"trackViewUrl": "https://itunes.apple.com/us/podcast/nerdcast/id381816509?mt=2&uo=4",
"artworkUrl30": "http://a5.mzstatic.com/us/r30/Podcasts/v4/e1/95/35/e1953536-8437-834e-eac8-01147ae11c9e/mza_3422052630315608394.30x30-50.jpg",
"artworkUrl60": "http://a4.mzstatic.com/us/r30/Podcasts/v4/e1/95/35/e1953536-8437-834e-eac8-01147ae11c9e/mza_3422052630315608394.60x60-50.jpg",
"artworkUrl100": "http://a1.mzstatic.com/us/r30/Podcasts/v4/e1/95/35/e1953536-8437-834e-eac8-01147ae11c9e/mza_3422052630315608394.100x100-75.jpg",
"collectionPrice": 0,
"trackPrice": 0,
"trackRentalPrice": 0,
"collectionHdPrice": 0,
"trackHdPrice": 0,
"trackHdRentalPrice": 0,
"releaseDate": "2014-05-16T12:12:00Z",
"collectionExplicitness": "notExplicit",
"trackExplicitness": "notExplicit",
"trackCount": 301,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Society & Culture",
"radioStationUrl": "https://itunes.apple.com/station/idra.381816509",
"artworkUrl600": "http://a2.mzstatic.com/us/r30/Podcasts/v4/e1/95/35/e1953536-8437-834e-eac8-01147ae11c9e/mza_3422052630315608394.600x600-75.jpg",
"genreIds": [
"1324",
"26"
],
"genres": [
"Society & Culture",
"Podcasts"
]
},
.....
I'd like now to get all episodes from that first result. I've tried to do a lookup request using the collectionId, but it just returns back the same output as above instead of all podcasts from that collection.
https://itunes.apple.com/lookup?id=381816509&entity=podcast
From reading the documentation and some other posts this is how I believe it should work, but it doesn't. Is anyone able to help me out? Thanks.
I think what you need to do is to take that feed URL and get the tracks from there directly
"feedUrl": "http://jovemnerd.com.br/categoria/nerdcast/feed/",
I suspect that the iTunes search API documentation and implementation contain caveats that are not written clearly out.
For me, this works. I use this code:
https://github.com/ijanerik/PHP-iTunes-API/blob/master/README.md
foreach($results as $item){
$url = $item->feedUrl;
}
$xml = simplexml_load_file($url) or die("feed not loading");
print_r($xml);

Facebook API How To Get All Pages I Like Without Pagination

If I like more than 100 pages/things, FB.API('me/likes') returns 99 items and a link to the next paging.
Is it possible to get ALL without the pagination?
Thanks
Have you tried /me/likes?limit=999 ?
You may still need to paginate, but you should be able to get more than 99 items in a single call
Use FQL:
$fql = "SELECT page_id from page_fan where uid = me())";
$pages_i_liked = $facebook->api(array(
'method'=> 'fql.query',
'access_token' => $access_token,
'query'=> $fql,
));
print_r($pages_i_liked);
Get All facebook pages of a user using facebook api
required permissions: manage pages
type: GET
url: https://graph.facebook.com/me/accounts
param: access_token
responce of the above request like this
{
"data": [
{
"category": "Book",
"name": "Mind blowing books",
"access_token": "CAACEdEose0cBAFRU2j0rGgNxBcJvU0pkZCpDbI7rZCJNmO2cZAfZBXoejoZCdTVdKi4gNCyBuu9fPRnWRAwCKrmkPePzKHoE5e46Jz7gRDYe3PM5ECm0ZC5OZB2iWLeEh3OZBgTGfWDmQbbFivwlp5v2umc0CcC9JlTvHsWDnTZCkKIbZAJeD2nOus1ZCCXMqSXHOAZD",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
],
"id": "618353601555775"
}
],
"paging": {
"next": "https://graph.facebook.com/100000328561058/accounts?access_token=CAACEdEose0cBADKMTNRBl5pjNhw8xsKnQf57XKShV7UlhGyJy67bBZCUKkepl9rELlxqq0I474f8LEPGnt51Mdgs0MMtgTycuUgkOyRnLgVypWVpBd7oKy3LXrrbsQWSdIUZBU4qKHLxSb14TP8ySOaZChLseseYMr1YMLG3qrJiWLuwWJeVz2PeE8TmkkZD&limit=5000&offset=5000&__after_id=618353601555775"
}
}
Post at specific facebook page of a user using facebook api
required permissions: piblish action
type: Post
url: https://graph.facebook.com/{PAGE_ID}/feed
param: access_token, message
this http request will write your message on fb page
PAGE_ID: its page id which is in responce of first request
The maximum results limit is 100
"I just noticed this while counting the results and also next page query, if I insert limit 999 for example, the exact results will be shown as 100 and the next link generated by facebook will contain the limit value also 100"
With this class from Github: FacebookLikedPagesAPI you can get all ID liked pages on Facebook without pagination
$access_token = '';// your access token here
$likes=new Likes();
$result=$likes->getAllLikedPages($access_token);