List collaborators from GraphQL API - github

I'm trying to list collaborators for all repos in an organization. My query looks like this.
query($login: String!, $cursor: String) {
organization(login: $login) {
url
login
repositories(first: 100, after: $cursor) {
pageInfo {
endCursor
hasNextPage
}
nodes {
name
collaborators(affiliation: OUTSIDE, first: 100) {
edges {
permission
}
nodes {
url
login
name
email
company
}
}
}
}
}
}
This works fine in the GraphQL Explorer. No permissions errors as my user has the necessary permissions.
However if I try to do this from the GraphQL API endpoint directly, I get:
[
{
"type": "FORBIDDEN",
"path": [
"organization",
"repositories",
"nodes",
0,
"collaborators"
],
"locations": [
{
"line": 18,
"column": 21
}
],
"message": "Must have push access to view repository collaborators."
},
I have given my personal access token all possible scopes to debug, the issue persists.
Since my user is org admin and can list all collaborators from the GraphQL Explorer, I would expect this to work.

I have given my personal access token all possible scopes to debug, the issue persists.
Nevertheless, if you don't have push/write access to those repositories, you would get that error message, irrespective of the scopes you gave to your token.
(as illustrated here)
See also isaacs/github issue 444 for confirmation.

Related

Which private repos have GitHub Pages

I want to downgrade my GitHub account to the free plan. GitHub warns me that I have one private repository that uses GitHub Pages - a feature that the free plan doesn't support. So I want to find this repo to see if it is problematic if it becomes public.
I can't find any way to even list my repos that use Github Pages, let alone the ones that are private.
Is there a way to do this?
Yes, simple via GraphQL API, with or without GraphQL API Explorer, (don't forget personal access token scope if using without the explorer,) if you don't have very much private repos.
Use query:
query {
viewer {
repositories (first:100, privacy: PRIVATE) {
nodes {
name
deployments (first: 1) {
nodes {
environment
}
}
}
}
}
}
Example result:
{
"data": {
"viewer": {
"repositories": {
"nodes": [
{
"name": "repo-without-pages",
"deployments": {
"nodes": []
}
},
{
"name": "repo-with-pages",
"deployments": {
"nodes": [
{
"environment": "github-pages"
}
]
}
}
]
}
}
}
}
Typically the only possible environment is github-pages. If you have more, change the above query.
Note GitHub GraphQL API has a limit: Values of first and last must be within 1-100. If you have more than 100, use:
repositories (first:100, privacy: PRIVATE) {
pageInfo {
endCursor
}
and after getting endCursor:
repositories (first:100, privacy: PRIVATE, after:"endCursorValue==") {
pageInfo {
endCursor
}
to paginate.

Facebook graph api unable to get some properties like admin_notes, labels or custom_labels in comments listing

We are building an app that manage Facebook comments for page admins. When managing the comments, we want to know if there is any "admin_notes" or "custom_labels" that the page admin has previously applied on that specific owner of the comment.
I imagine the API is something like this:
https://graph.facebook.com/v3.3/45013343238491111/comments?order=reverse_chronological&fields=message,from{name,id,custom_labels,admin_notes,likes}&access_token=...
The api above should theoretically return list of comments made on a post, with their owners name, id, and custom_labels etc.
But the comment listing response is like this:
{
"data": [
{
"message": "sdfsdfsdf",
"from": {
"name": "Dora Chan",
"id": "23424292416969420",
"likes": {
"data": [
{
"name": "Page name",
"id": "XXXXXX",
"created_time": "2019-05-29T06:03:42+0000"
}
],
"paging": {
"cursors": {
"before": "Mzg5OTgwNzQ4MjcxNzU3",
"after": "Mzg5OTgwNzQ4MjcxNzU3"
}
}
}
},
"id": "450133432384921_450162525715345"
},
{....
Information like "page likes" is available. But information like admin_notes and custom_labels are not available.
Why is that so?
Note:
I am using page access Token. All page related permissions are granted:
manage_pages, pages_show_list, publish_pages, pages_messaging, public_profile
If I call graph API on that specific user directly, i.e. https://graph.facebook.com/v3.3/[userid]?fields=name,id,likes,custom_labels&access_token=...
The outcome is same, I can see only name, userid, likes, but I cannot see custom_labels

Permissions to Read Likes via Graph API

Since the REST API has gone, I need to find another way to read the likes for pages of our webapp.
According to the Graph API docs, the following should return the likes for any object (such as a page):
https://graph.facebook.com/v2.6/{PAGE-ID}/likes?summary=true
Oops, An access token is required to request this resource. Turns out, instead of a real token, you can also build an ad-hoc token witht the app ID and secret:
https://graph.facebook.com/v2.6/{PAGE-ID}/likes?summary=true&access_token={ID}|{SECRET}
The above returns a JSON payload, however, it's empty even though I'm trying this with a page having almost 200 likes:
{
"data": [
],
"summary": {
"total_count": 0,
"can_like": false,
"has_liked": false
}
}
Maybe a permissions problem? The app domain and the page URL domain are identical.
Big thanks for any hints to solve this riddle!
It does work with a simple App Access Token too, but i assume you get the wrong idea about that endpoint. There is no way to get the "Page Fans", you can only get "other Pages the current Page likes" with it. Just try this with your App Access Token:
https://graph.facebook.com/bladauhu/likes?access_token=APPID|APPSECRET
It should return the following JSON:
{
"data": [
{
"name": "FKK Scibes Skulls",
"id": "1391253501090151"
},
{
"name": "Dodgeball Austria",
"id": "387249994631552"
},
{
"name": "Turbojugend Scibes",
"id": "105248832848054"
},
{
"name": "HYDRA! Das endgute Satiremagazin.",
"id": "167084486537"
},
{
"name": "VLÜ Hydra",
"id": "113680962002559"
}
],
"paging": {
"cursors": {
"before": "MTM5MTI1MzUwMTA5MDE1MQZDZD",
"after": "MTEzNjgwOTYyMDAyNTU5"
}
}
}
More information about Tokens:
http://www.devils-heaven.com/facebook-access-tokens/
https://developers.facebook.com/docs/facebook-login/access-tokens/
https://developers.facebook.com/docs/apps/changelog#v2_6_changes:
The likes field on the Page node has been renamed to fan_count
As luschn said in their answer, likes are the other pages liked by that page; if you want to get the number of people that like the page itself, you need to request fan_count.

Getting the user context id for a Facebook Open Graph API query

I'm currently building an experimental social network to study the influence of social medias on customers behaviors.
My users log in through Facebook OAuth provider. I store their access tokens and query the Open Graph API to fetch info about them.
I'm trying to use the all_mutual_friends edge for a given user context, using the access token of one of my users, but I found nowhere how to get the user-context-id that is required to get that info.
It is not the id of the user you want to retrieve the mutual friends from. I've tried that and got an error.
I've skimmed trough Open Graph docs and found nothing about that user-context-id.
How can I retrieve it?
Odly enough, the docs do not specify how to get the context id, but I managed to get it by digging a little.
This is how you would do to get the all_mutual_friends data:
GET /{user-id}?fields=context.fields%28all_mutual_friends%29&access_token={other-user-access-token}
Then, the context id would be given in the response.
{
"context": {
"all_mutual_friends": {
"data": [
{
"id": "1381033095543871",
"name": "Dave Amiaaehjighi Putnamwitz",
"token": <user token>,
"picture": {
"data": {
"is_silhouette": true,
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/c15.0.50.50/p50x50/10354686_10150004552801856_220367501106153455_n.jpg?oh=82c2ce067f9c7f2c0a66d1efb16730e7&oe=5670F72F&__gda__=1450287355_17925d7381c8da5663c2349483f4b032"
}
}
}
],
"paging": {
"cursors": {
"before": "MTM4MTAzMzA5NTU0Mzg3MQZDZD",
"after": "MTM4MTAzMzA5NTU0Mzg3MQZDZD"
}
},
"summary": {
"total_count": 1
}
},
"id": <Context id>
},
"id": "1375274282788732",
}
That context id could then be used for
GET /{user-context-id}/all_mutual_friends/
But this step is pretty useless since we get the data in the first query.
Would be nice if Facebook updated their docs to reflect reality.

Retrieve comments on Facebook ads through the API

Is it even possible to retrieve comments on Facebook ads through the API (Graph or FQL)? If yes, do I need a whitelisted app to do it? Also, if I have a page access token, is it enough, or I need a user access token with ads_management permission?
Regarding the token usage, a page_token is extended by a given user to a given app. The page_token will have at most the same privileges as the user on his authorized pages and ad_accounts.
Generating a page_token can be done automatically, in behalf of the user, if you already have a user_token with manage_pages permission. Again, this page_token will have at most the same privileges that the user_token you used to generate it.
In other words, having a page_token doesn't amount for any additional privileges than the ones already present in the user_token.
Having said that, you need
a token with access to a given ad_account
that the app for which that token was generated, has that ad_account active in its settings
If the second requisite isn't met, for example for ad_account act_123456789 you'll get the error:
{
"error": {
"message": "(#274) The ad account is not enabled for usage in Ads API. Please add it in developers.facebook.com/apps -> select your app -> settings -> advanced -> advertising accounts -> Ads API. Account 123456789 not enabled for this application.",
"type": "OAuthException",
"code": 274,
"fbtrace_id": "xxxxx"
}
}
You can try, for example, generating a token with all privileges for the Graph API Explorer App. It will throw the error above because said App doesn't have the ad_account act_123456789 enabled.
So, given you have a token with ads_read extended for an app that has this ad_account listed, and you know the ad_id, you can procede as I explained in thread Get comments from facebook ads (marketing)
Basically, you use the ad_id (for example 123000000) to get the promoted post id and its actions
/123000000?fields=creative.fields(effective_object_story_id),insights.fields(actions)
The answer will contain an effective_object_story_id (for example, let's say it is 456000000_789000000) and its actions broken down by type:
{
"creative": {
"effective_object_story_id": "456000000_789000000",
"id": "123000000"
},
"insights": {
"data": [
{
"actions": [
{
"action_type": "comment",
"value": "12"
},
{
"action_type": "like",
"value": "2"
},
{
"action_type": "post",
"value": "3"
},
{
"action_type": "post_reaction",
"value": "29"
},
{
"action_type": "video_view",
"value": "558"
},
{
"action_type": "page_engagement",
"value": "604"
},
{
"action_type": "post_engagement",
"value": "602"
}
],
"date_start": "2017-08-14",
"date_stop": "2017-08-20"
}
],
"paging": {
"cursors": {
"before": "xxx",
"after": "xxx"
}
}
}
}
If you want to also distinguish paid comments from regular comments, you can query the comments edge of the post_id 456000000_789000000 to get the overall comment count which should be greater than the comments generated by the ad.
You can't pull the actual words of the comment via the API - would make it too easy to scrape.
Yes, Facebook ads that have comments are because the ad is a promoted page post, whether that page post is hidden or not. Page post comments are available via the Facebook API and does not require having Ads API access. Use the graph API endpoint /v2.1/{page-id}/comments to retreive page post comments. See the Facebook Graph API documentation on object comments for more information.