Gist / Github API - get private and public Gists

2019-07-07 03:04发布

问题:

I am trying to list all gist from a group of users using the github api. This is working really well but I can't seem to get it to return private gists for myself or any others users.

I know that you can set scope in the request but I don't get how I would set this in my JQuery request and what scope should I use to get private gists?

Some of my code is below:

var the_url = 'https://api.github.com/users/'+ encodeURIComponent(user) +'/gists';

      $.oauth ({
        consumerKey: 'xxxxxxxxxxxxxxxxx', 
        consumerSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 
        type: "GET",
        url: the_url,
        data: {},
        dataType: 'json',
        async: false,

回答1:

You'll need a user to grant access via oAuth.

You can read public gists and create them for anonymous users without a token; however, to read or write gists on a user’s behalf the gists oAuth scope is required.

http://developer.github.com/v3/oauth/#scopes