3

I try to use github api to star a repo:

curl -X PUT -H "Authorization: token *****************"     https://api.github.com/user/starred/fulldecent/system-bus-radio

but the response is always

{
 "message": "Not Found",
 "documentation_url": "https://developer.github.com/v3"
}

And I also try alamofire

Alamofire.request(.PUT, "https://api.github.com/user/starred/"+repoFullName, headers: ["Authorization": "token \(token)"]).responseJSON{ response in
    ......
}

But I still can't get it done

陈敏华
  • 1,365
  • 1
  • 9
  • 9

2 Answers2

0

There are a couple of reasons why you could get a 404 "Not Found" error.

First reason is of course that the endpoint you are trying to use does not exists, but from the docs it seems like you are using it correctly.

Additionally, the GitHub API returns 404 even in cause of authorization errors, instead of returning a 403 as one would expect (see documentation). It is possible that the token you are trying to use is not valid, or that the user doesn't have access to that repository, or that the token doesn't match the user, or any other possible authorization problem.

Marco83
  • 1,181
  • 1
  • 10
  • 28
0

If you want to use put, you need to give permission to repo scope when authorize.

For example when using oauth github.

Step 1: Create your oauth github app

Step 2: You got client_id, put this source link in your apps for user to oauth from github https://github.com/login/oauth/authorize?scope=user:email&client_id=<client_id>&scope=repo Step 3: When callBackUrl, follow this to get access token

https://developer.github.com/v3/guides/basics-of-authentication/#providing-a-callback

Last Step: You can do starring by just passing ?access_token=xxxxxxxxxx

Oktaheta
  • 606
  • 5
  • 21