Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add OAuth example to readme (#219) #221

Merged
merged 5 commits into from
Aug 17, 2016
Merged

add OAuth example to readme (#219) #221

merged 5 commits into from
Aug 17, 2016

Conversation

thisconnect
Copy link
Contributor

No description provided.

method: 'GET'
};

got(request_data.url, {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to specify the json: true option

@thisconnect
Copy link
Contributor Author

@sindresorhus I'll close this and open a new PR (squashed) ok?

@julien-f
Copy link
Contributor

@thisconnect, @sindresorhus can squash on merge, I don't think you have to create a new PR.

@thisconnect
Copy link
Contributor Author

nice to know, thanks :)

@thisconnect
Copy link
Contributor Author

thisconnect commented Aug 16, 2016

BTW: option.query can NOT be used with OAuth as the query has to be part of the requestData.url in oauth.authorize

@thisconnect
Copy link
Contributor Author

alternative:

const got = require('got');
const OAuth = require('oauth-1.0a');

const oauth = OAuth({
    consumer: {
        public: process.env.CONSUMER_KEY,
        secret: process.env.CONSUMER_SECRET
    },
    signature_method: 'HMAC-SHA1'
});

const token = {
    public: process.env.ACCESS_TOKEN,
    secret: process.env.ACCESS_TOKEN_SECRET
};

const url = 'https://api.twitter.com/1.1/statuses/home_timeline.json';

got(url, {
    headers: oauth.toHeader(oauth.authorize({ url: url, method: 'GET' }, token)),
    json: true
});

@sindresorhus
Copy link
Owner

👍

{ url: url, method: 'GET' } => {url, method: 'GET'}

const url = 'https://api.twitter.com/1.1/statuses/home_timeline.json';

got(url, {
headers: oauth.toHeader(oauth.authorize({ url, method: 'GET' }, token)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove spaces inside the object {url, method: 'GET'}

@sindresorhus sindresorhus merged commit 7ed62b1 into sindresorhus:master Aug 17, 2016
@sindresorhus
Copy link
Owner

Looks great! Thanks @thisconnect :)

@thisconnect
Copy link
Contributor Author

Thank you too!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants