How to get a single gist from github with GET /gists/:id - github

Somehow I fail to get a single gist from github.
Lets say i would like to get the following gist: https://gist.github.com/jrm2k6/6637633
Just copy&paste in URL field of your browser.
With https://api.github.com/users/jrm2k6 I can get the users info as json.
With https://api.github.com/users/jrm2k6/gists I can list all the public gists from this user as json.
But how do I get a specific gist GET /gists/:id with the id = 6637633 like it is described here in the api documentation: http://developer.github.com/v3/gists/#get-a-single-gist
With https://api.github.com/users/jrm2k6/gists/6637633 I should receive the content of the gist as json but instead I receive an error
{
"message": "Not Found",
"documentation_url": "http://developer.github.com/v3"
}
What am I doing wrong?
SOLUTION: You do not need the /users/:user. Working: https://api.github.com/gists/6637633

The documentation for all gists mentions
GET /users/:user/gists
Notice that the documentation for a single gist mentions
GET /gists/:id
so you do not need a user. https://api.github.com/gists/6637633 will work.

Related

Using the ScanR API from gouv.fr for a POST request that, given a company name, returns its id

I'm trying to use the ScanR API:
Technical documentation: https://scanr-api.enseignementsup-recherche.gouv.fr/api/swagger-ui.html
General presentation: https://api.gouv.fr/les-api/scanR
Online interface: https://scanr.enseignementsup-recherche.gouv.fr/
My goal is to give the API a structure/company name, and receive, among others, a structure/company id. Then I am able use the GET endpoint '/v2/structures/structure/{id}' to access the description.
I believe that to do this, I would use the POST endpoint '/v2/structures/search'.
However, I don't manage to structure the query in a way that works.
Can anyone give me an example?
The scanR team kindly provided an example that I share here:
url_structures = "https://scanr-api.enseignementsup-recherche.gouv.fr/api/v2/structures/search"
my_query = "carbon\ waters"
params = {
"pageSize": 12,
"query": my_query
}
scanr_output = requests.post(url_structures, json=params).json()

How to get a working document preview link from MS Graph

I am trying to get a preview link for the useres recent documents over MS Graph. Unfortunately the link the endpoint returns does not work.
To get the informations about a file I first call GET https://graph.microsoft.com/beta/me/drive/recent. Then I copy the driveID and the id of a document from the parentReference property.
To get the preview link I use the Endpoint POST https://graph.microsoft.com/beta/drives/<DriveID>/items/<DocumentID>/preview
and this works fine. But when I click on the link I get the error "This item might not exist or is no longer avaiable". The document exists on the SharePoint, otherwise it would not appear under "recent documents". The url looks like this: https://www.onedrive.com/embed?webUrl=xyz.sharepoint.com/sites/nameOfTheSite/docLibName&id=sites/nameOfTheSite/DocLibName&embed=xxx&authToken=xxx
I expect the response of the /preview endpoint should return a working url. Do I have to make some configurations on O365?
Many Thanks
The embed link (preview) does not look valid in your example since id parameter refers to container (library): sites/nameOfTheSite/DocLibName. It is not supported, instead embed link should refer to a file
Most likely the issue is due to itemId:
https://graph.microsoft.com/beta/drives/<DriveID>/items/<DocumentID>/preview
^^^^^^^^^^^^
in your example it seems refers to a library instead of a file. Make sure the proper itemId is specified.
For example, https://graph.microsoft.com/v1.0/me/drive/recent endpoint returns the following payload:
{
"value" : {
//another properties are omitted for a clarity
//...
"remoteItem": {
"id": "01ECKZLCWSR7F76B64KZFL7I3QGZVPJELU"
//...
"parentReference": {
"driveId": "b!79yKq-2MdkSDnQ7_1Pf3FOkRyDCajpRIvqtA7UrsEO-vu3D_qkpaT50Y6CMcSmFv",
"driveType": "documentLibrary",
"id": "01ECKZLCV6Y2GOVW7725BZO354PWSELRRZ"
},
}
}
}
where
remoteItem.Id - corresponds to item id for a file
remoteItem.parentReference.driveId - corresponds to drive id
Dont get confused with remoteItem.parentReference.Id which corresponds
to item id of library

Unable to retrieve 'ContentId' property of Attachment in Office365 REST Api

I'm trying to retrieve attachments in the Office365 rest api. Since I want to avoid downloading the entire attachments, I'm using a select clause to avoid downloading the content, which is in the ContentBytes property:
$select="ContentId,ContentType,Id,IsInline,Name,Size"
So basically, I want to retrieve everything except the content. However, this gives the following error message (json):
{
"error":
{
"code": "RequestBroker-ParseUri",
"message": "Could not find a property named 'ContentId' on type 'Microsoft.OutlookServices.Attachment'."
}
}
It's telling me that ContentId doesn't exist, which contradicts the specifications.
Edit: Here is the full request:
GET /api/v2.0/me/messages/AAMkAGZlZjI3N2I3LTg1YWUtNDFiNC05MGI0LTVjYTVmZGI5NGI2YQBGAAAAAABzr8uDji9LRqgTCEsDv22wBwBWTXbvZW0dTKuxUGxpK4-lAAAAAAEMAABWTXbvZW0dTKuxUGxpK4-lAAC5QnKBAAA=/attachments?%24select=ContentId%2CContentType%2CId%2CIsInline%2CName%2CSize
Even more strange, when I do the same query without specifying any select clause, it returns me a full attachment object, including a ContentId.
Anybody can help?
In case anyone has the same question for microsoft graph, you need to pass this filter:
$select=microsoft.graph.fileAttachment/contentId
like this:
GET https://graph.microsoft.com/v1.0/me/messages/attachments?$select=microsoft.graph.fileAttachment/contentId
The request that you posted is getting the message specifications but not the attachments. Since you need to get the content id, you need to add /attachments to the request with any required parameters.
GET https://outlook.office.com/api/v2.0/me/messages/{message_id}/attachments/{attachment_id}
So please add the attachments to your query to be able to get the content id.
Hope this helps.
Solved it. The answer was suggested by Brian's comment and I found an additional hint here.
Since 'ContentId' is a property of a FileAttachment, you need to specify that in the request, like so:
$select="Microsoft.OutlookServices.FileAttachment/ContentId,ContentType,Id,IsInline,Name,Size"
That did the trick. Thanks for the suggestions.

Facebook Graph API event-id/comments?since=2014-02-01&until=2014-02-10 , Date filter has no effect

I am trying to bring comments made on a particular event by targeting this URL: https://graph.facebook.com/1466384840257158/comments
I am passing the user_access_token
I have two comments at present on this event made on the same
day(2014-03-29)
Now I try to pass a date which should bring an empty data result/object
like this: https://graph.facebook.com/1466384840257158/comments?since=2011-01-01&until=2014-01-10
This request has no effect, it still shows me the two comment made
on the 29th
I have tried the same kind of date range on my user-id/feed and it
gave me an empty data object.
Finally i tried event-id/feed (before trying date filter) and it
gave me the following error
.
{
"error": {
"message": "An unexpected error has occurred. Please retry your request later.",
"type": "OAuthException",
"code": 2
}
}
Could you please guide me about date filter on that particular query (point4) or if you have any other idea to use date filter on comments made for an event.
Comments use Cursor-based Pagination, so you cannot use since or until on the comments endpoint (these parameters would work f.ex. for the feed endpoint).
To get the comments in a time range you have to fetch all comments from NOW to the start of the time range, f.ex. with https://graph.facebook.com/1466384840257158/comments?filter=stream&limit=1000+paging (the filter=stream will order the result with the timestamp).
USING SINCE UNTIL FOR COMMENTS on GROUP
If you want to use since and until for comments, it is not possible directly for a group. So, First you can apply it for status(feed) and then get the comments for that feed.
This works for me:
{group_id}/?fields=feed.since(08/25/2016).until(08/31/2016){from,comments{from,message}}
Why don't you try first to filter by notifications?... notifications allows you to add parameters like since. For example (using Facebook pages):
https://graph.facebook.com/PAGEID?fields=notifications.since(2015-3-31 00:00:00).limit(250).include_read(true)&{id,created_time,updated_time,unread,object,link}&access_token=ACCESSTOKEN
Once you got the json data, loop through data, get the ID and send a second request but this time using the PAGEID_POSTID edge. Something like this:
https://graph.facebook.com/PAGEID_POSTID/comments?fields=id,from{name,id},message,can_remove,created_time&limit=1000
Voahla!... there's no need to read every comment!...
Note 1: A Page access token is required, along with the manage_pages permission
Note 2: Use the parameter/field include_read to get all the notifications, even the already readed
Note 3: In the second request, use the parameter/field "filter=stream" to order the posts and get the comments made in the name of your page
Note 4: Don't forget to control the asynchronicity once you loop!
Note 5: Notifications duplicate posts, use an array to avoid to read more than one time the postUse the parameter/field include_read to get all the notifications, even the already readed
I do not know if it's too late. But, Yeah it works in the graph api version 3.3.
for example: if you wanna get comments on a post of a Facebook page you can do it like this:
You have to use page Access-token
The get Graph Request : post_id/comments?since=some_date

Facebook Graph API - Searching in public posts

Is there a way to search for 2 keywords in a public post? I want to do a full text search in all public posts.
Right now I am doing it as "https://graph.facebook.com/search?q=A+B&type=post&fields=link,message&access_token=<>.
Current Behavior: fetching posts having A or B.
Required Behavior: Fetch post have both A & B.
I have also tried POST method in Graph API Explorer. Please suggest what should I do to get results.
Other things I tried :
facebook graph api search rules. But it also seems not working, even when I tried with q=A&q=B. Only second query word is getting searched.
Use the '|' operator. In your note, 'q=A&q=B' you are reassigning the value of 'q'. The API parses the string set as the value for 'q' and uses the '|' operator to parse between. Either way you will have a tough time finding a lot of results because the 'search/post' API is now deprecated.