hellow fellows iam creating a program that willbe able to get all repository in a github account of specifc loged in user,i sucessfully authenticate the user but the problem is how i could get the repositoryies of authenticated user the code below has full details on how i did it, but still icant get the repositories,also for the end point link what shall i add there ineed your help
This view fetches repositories of the authenticated user from GitHub
Retrieve the access token from the session after OAuth authentication
def github_repositories(request):
access_token = request.session.get(‘github_access_token’)
# Check if the access token exists
if access_token:
# Set up the headers for GitHub API request
headers = {
'Authorization': f'Bearer {access_token}',
'Accept': 'application/vnd.github.v3+json'
}
# Make a GET request to GitHub API to fetch user repositories
response = requests.get(' https://api.github.com/orgs/ORG/repos', headers=headers)
# Check the response status code
if response.status_code == 200:
# Parse the JSON response to extract repositories
repositories = response.json()
# Pass repositories to the template
return render(request, 'dashboard.html', {'repositories': repositories})
else:
# Handle API request errors
return HttpResponse('Error fetching repositories', status=response.status_code)
else:
# Redirect the user to log in with GitHub if the access token is not found
return redirect('github_login')
iam execting solutions responses from you also you may email me through [email protected]
francis john is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.