how to star a repo with github api

Viewed 2270

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

2 Answers

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

Related