GitHub API find all commits by user ID with timestamp - github

Is there an efficient way to find all recent commits by a specific user across all public repos?
I am currently use /events/public and filtering out those event.type === "PushEvent". However this is not very efficient because
The commits in the PushEvent does not have timestamp, which means I need additional requests to fetch their timestamps through commits[][url].
There is a limit of 60 requests/hour which gets quickly used up because I need to fetch timestamp of each commit.
Is there any better way to do this?

No unfortunately there is no better way to retrieve commits for the user.
However there is a workaround for the rate limit:
Documentation says
For requests using Basic Authentication or OAuth, you can make up to 5,000 requests per hour. For unauthenticated requests, the rate limit allows you to make up to 60 requests per hour.
You can generate an access token and use it as an OAuth token.
How to use token
If you're going to use Basic Authentication
you need to add new header
Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l
where the string after Basic is a Base64 encoded string of
your_user_name:your_token
If you're using curl
curl -u username:token https://api.github.com/user
or
curl https://username:token#api.github.com/

Related

Http Get vs Http Post to get data, which one is recommended?

recently I come across an issue that I don't know which is a good (standard) way to handle it in REST Api.
The problem is very simple. We all know that in standard REST Api, we use Get request to get data and Post request to send data to server to create/update resources.
For that, if we want to get a list of all users in our application, we would use a GET request with url like this: HTTP GET /users
That's easy right. Let's get to our scenario. Our application allows users to create their own post and people can comment, like, or follow posts created by them or other users. On top of that, we have billions of existing users.
Now, let's say we have a post that has been interacted with thousands of users (popular post) and we want to return that list of users. For this to work, we would at least need to send to server the post Id to look up. Obviously, we do not want to return a list of thousands of users at one time. That would be too much for front end to handle. For that, we would introduce a pagination number and page size to limit the number of users returned. Therefore, on top of the post Id, we will need to send page number and page size as well.
Now, we will have two ways to construct our request:
GET request: /users?postId=123&pageNumber=1&pageSize=10
POST request /users with body request
{
"postId": 123,
"pageNumber": 1,
"pageSize": 10
}
GET seems to be a standard one because it is querying and returning data to front end, but again, the postId is exposed to public.
POST, on the other hand, is a bit more safer since parameters do not store in browser
Which one is the more standard one and recommended in this case ?
Use Get.
What concerns you about the post id appearing in a URL?
If all relevant endpoints are secured, there's nothing a user can do with that id unless authenticated and authorized to perform an action on that post.
Besides, the body of a posted request can be viewed in the browser's dev tools so a post just obfuscates the data a little. It doesn't actually secure it.
Get.
You should Secure the program so that it is not misused.
If you send a post request to get thousand data, your server go down.
you should use get and pagination to get best result.

GitHub API - Get commit details via access token

With the GitHub API, let's say I have used OAuth and I have the client secret of a user. Let's say I also have a repo, say myname/project, as well as a commit ID, say asdfghjkl123. With this information, I know I can get the details of the commit, but how can I do this on "behalf" of the user? Basically, I want to use the access token I have so that the rate limit is based on the user. Is this even possible?
As illustrated in this issue
A way to provide a GITHUB_AUTH_TOKEN env var which is attached to GitHub requests to avoid api limits, as in this PR
I always set GITHUB_AUTH_TOKEN to my token before making my curl GitHub API calls: I then benefit from an higher rate limit.

Get All Issues on GitHub repository in specific month using GitHub API

I am trying to get all Pull requests created by specific user in a specific month in my django application using GitHub API.
e.g:
https://api.github.com/repos/myrepo/example/issues?creator=person_name&start_date=2018-1-1&end_date=2018-1-31
You can find issues created by a user in a given month using the search issues API endpoint, e.g.
https://api.github.com/search/issues?q=author:username+created:2018-01-01..2018-01-31
created can take a value like YYYY-MM-DD..YYYY-MM-DD to set a date range.
You might also want to add type:issue so you don't see pull requests or repo:user-or-org/repo to restrict results to a single repository.
Note that there are restrictions on searching users' contributions, including issues. You may need to have your users authenticate before you can search their issues. You should be able to try the endpoint out with your own user account, as long as you've got an authenticated session (e.g. by using a search URL in a browser where you're logged into GitHub).

REST API - Post Requests to Query Active Directory

My company is currently writting a REST API where they allow querying for Active Directory specific information via a POST requests.
In the request body the following information gets sent to the API:
Filter (LDAP)
Properties to return (e.g userAccountControl, sAMAccountName)
From a personal point of view I would have definitely realised it via simple GET methods.
Is the POST method approach the recommended way to so? Are there any particular reasons to implement it with POST?
I can see slight advantages of using a POST request. It is certainly more secure for sending any sensitive data, because the body of the request is not cached by the user's browser and other network devices on the way. Also a POST request allows you to send an unlimited amount of data, but that is probably not relevant for this use case.

Get latest tweets for multiple screen_names through Twitter Rest API in CURL

I'm completely new to the Twitter Rest API. I have generated a curl command using OAuth tool in twitter to get the tweets posted by a single user.
curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' --data 'count=2&screen_name=twitterapi' --header 'Authorization: OAuth oauth_consumer_key="AAAAAAAAAAAAAAAAAAAA", oauth_nonce="BBBBBBBBBBBBBBBBBBBBBBB", oauth_signature="CCCCCCCCCCCCCCCCCCCCCCCCCCC", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1471672391", oauth_token="DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", oauth_version="1.0"'
Reference: https://dev.twitter.com/rest/reference/get/statuses/user_timeline
I got the data for a single screen_name and now I would like to pull the tweets for multiple screen_names at once through Curl.
I have tried this using POST but it didn't work. I have been trying since 7 days.
Can anyone help me to resolve this ?
Thanks in Advance.
Aswin
As far as I know this is not possible with one API call. The operation you are referencing only allows for the retrieval of statuses by a specific user, not multiple users. Also, it requires a GET request so a POST won't get you very much.
You can look at other operations to see if they fit your requirements. For example GET statuses/home_timeline gets the statuses of all users that are followed by the account with which you request this.
However if the users whose statuses you are looking to retrieve have nothing like this in common than the best way to go is to use separate requests for each user and use the API as intended.