Here's a function in Matlab to retrieve a user's SSH key from their GitHub account using GitHub API:
main.m590 chars23 lines
This function takes in two inputs:
username
: the Github username of the person whose ssh key we want to retrievetoken
: a personal access token with read:user
scope generated from the Github account settingsThe function then constructs the API url to retrieve the SSH keys of the user, sets up options for the http request including header fields and content type, and sends a GET request to the GitHub API.
If the response is successful, the function extracts the first SSH key from the response JSON and returns it as a string. If the response is empty or there are errors in the request, an empty string is returned.
gistlibby LogSnag