Coder Social home page Coder Social logo

goodreads-api-node's Introduction

A Goodreads API wrapper for node.js

Goodreads

Installation

npm install --save goodreads-api-node
const goodreads = require('goodreads-api-node');

Usage

You need to register your app to get a goodreads developer key With the developer key and secret you can now call goodreads(). This will return an object which exposes the API methods.

const myCredentials = {
  key: 'MY_GOODREADS_KEY',
  secret: 'MY_GOODREADS_SECRET'
};

const gr = goodreads(myCredentials);

API

Some of those API methods just need your key/secret. To make API calls on behalf of your user, you need to get their permission using oAuth. All methods on the goodreads object return an promise. The following methods all work without oAuth:

getBooksByAuthor(authorID, [page])

// returns all books by an author given the authorID
gr.getBooksByAuthor('175417')
.then(console.log);

This prints the following result:

 { id: '175417',
   name: 'Bruce Schneier',
   link: 'https://www.goodreads.com/author/show/175417.Bruce_Schneier',
   books: { start: '1', end: '25', total: '25', book: [Object] }
 }

You can pass an optional page parameter specifying the result page you want to get.

getAuthorInfo(authorID)
getAllSeriesByAuthor(authorID)
getUserInfo(userID)
getUsersShelves(userID)
getUsersGroups(userID, [sort])
getGroupMembers(groupID, [params])
searchGroups(query, [page])
getGroupInfo(groupID, [params])
getRecentReviews()
getReview(reviewID, [page])
getUsersReviewForBook(userID, bookID)
getRecentStatuses()
showBook(bookID)
bookIDtoWorkID(bookId)
getSeries(seriesID)
getSeriesByWork(workID)

searchBooks([params]);

@param {object} params q: query, page: page of results, field: one of 'title', 'author' or 'all' (default)

Example Usage:

  const res = await goodreads.searchBooks( { q: 'A song of ice and fire', page: 2, field: 'title' } );

OAuth authentication and methods

If you want to make requests on behalf of your user (e.g. them marking a book as 'read') you need to get their permission. The Goodreads API uses OAuth for this.

There are two ways to initialize the oauth process. You can either pass a callbackURL to the goodreads() function (which then calls initOAuth() for you) or you just call gr.initOAuth() after setting up your credentials. The callbackURL is not required for oauth to work, it's just used for goodreads to be able to redirect your user after granting/denying access.

// set callbackURL together with your key/secret
const gr = goodreads(myCredentials, callbackURL);

// or call initOAuth(callbackURL) after setting up your key/secret
const gr = goodreads(myCredentials)
gr.initOAuth(callbackURL);

After this you should be able to call getRequestToken() to obtain a requestToken. You need the requestToken to inform your user about your app wanting to make requests with his account.

gr.getRequestToken()
.then(url => { /* redirect your user to this url to ask for permission */ });

getRequestToken() returns (a promise which resolves) a URL. You can now redirect your user to this URL to ask him for access to his account. The callbackURL provided in initOAuth() is then used to inform you about whether the user granted access. Goodreads will redirect to this url with the query params oauth_token and authorize.

http://yourapp.com/goodreads_oauth_callback?oauth_token=ezBHZc7C1SwvLGc646PEQ&authorize=1

For further information about the goodreads OAuth process: Goodreads API Documentation

If the user granted access you can now request an accessToken from the goodreadsAPI.

gr.getAccessToken()
.then(() => { /* you can now make authenticated requests */ });

That's it! You can now use the following methods:

getCurrentUserInfo()
followAuthor(authorID)
unfollowAuthor(authorID)
showFollowing(followingID)
getUserFollowings(userID)
addBooksToShelf(bookID, shelfName)
followUser(userID)
getRecommendation(recommendationID)
getFriendRequests([page])
answerFriendRecommendation(recommendationID, response)
answerFriendRequest(requestID, response)
addFriend(userID)
joinGroup(groupID)
getNotifications([page])
getOwnedBooks(userID, [page])
deleteOwnedBook(bookID)
unlikeResource(resourceID)
deleteReview(reviewID)
getBooksOnUserShelf(userID, shelfName, [queryOptions])
getCurrentUserInfo()

Contribute

  • coming soon

goodreads-api-node's People

Contributors

akursat avatar baahrens avatar dependabot[bot] avatar grumpyoldman-io avatar kaizacorp avatar roeefl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

goodreads-api-node's Issues

seriesWorkIsIn is undefined

Hello,

The latest published version of your package isn't working because of a regression introduced in 71f48f5, where seriesWorkIsIn got renamed to getSeriesByWork, but not all references to it were properly updated.

Thank you for this project!

How can I add no-cors to header?

I am building a web-app with this module, and during development, I get an error saying the fetch couldn't be completed because of CORS.

Is there a way to add "no-cors" to header for development? (So that I can test my code on localhost)

searchGroups issue

searchGroups not showing up on goodreads-api-node.es.js or goodreads-api-node.umd.js files, even after running npm update on the package.

Apologize in advance if this is a local issue for me.

You have not passed shelfName

I'm trying to use gr.addBookToShelf() by keeping getting the error You have not passed shelfName. I used the default shelf, read and have tried other shelves such as to-read but the promise keeps being rejected.

I noticed there was a small typo in the readme. It should be gr.addBookToShelf() rather than gr.addBooksToShelf() which caught me out.

app.get('/book/add', function (req, res) {
    var addbook = gr.addBookToShelf({
        bookID: req.query.id,
        shelfName: "read"
    });
    addbook.then(function (result) {
        console.log(result);
        res.redirect("/");
    }).catch(function (err) {
            console.log("Adding book rejected" + err);
        });
});

Git Branch

New endpoint request

Hi,

I'm currently trying to access a endpoint that is not define in your module. The current one that i'm trying to access is '/book/show/'(https://www.goodreads.com/book/show/50.xml?key=...) .
This would give access to single book search which has some advantages one of them would be the language_code node for book.

Can you please add it or can i try and add it ?

Best Regards,
zapo

Typo in example in README

In the README under OAuth authentication and methods the example says:

gr.initOauth(callbackURL);

when the call should be:

gr.initOAuth(callbackURL);

with a capital 'A'.

No callBackURL

I'm having some issues using OAuth authentication and would appreciate any help you could provide. I keep getting the error initOAuth(): Warning: You have passed no callbackURL. I'm using the same URL I've defined when I created my API keys.

var callbackURL = "http://127.0.0.1/goodreads";
const gr = goodreads(myCredentials, callbackURL);
app.get("/authenticate", function (req, res) {
    gr.getRequestToken()
        .then(url => {
            console.log(url);
            res.redirect(url);
        }).catch(function () {
            console.log("Promise Rejected");
        });
});

Is it possible to add notes to a book with this library?

Thanks for making this great library!

Is it possible to add notes to a book on a bookshelf? It seems like it would be part of addBooksToShelf but I don't see anything related to the notes.

Attached is a screenshot example of what the notes look like on the website.

image

Thanks!

Not able to call showBook api

I am trying to use showBook API but it is returning nothing.
The issue is the URL returned by getRequestToken is invalid.
This is my code to getRequestToken.
const goodreads = require('goodreads-api-node'); const gr = goodreads(config.get('goodReads'), "https:\\\\www.wordsmaya.com"); gr.getRequestToken() .then(url => { console.log(url); });

And ourput printed is
https://goodreads.com/oauth/authorize?oauth_token=nVu0YBF8O51N2JWhC7n5w&oauth_callback=oob

How to get this working? My ultimate goal is to get a book details using isbn.

Get a book

Any way to get details of a book? Each book has an id.
You can currently get the details (in XML)
https://www.goodreads.com/book/show/135479?format=xml&key=[developer-key]
where 135479 is good reads book id.

getCurrentUserInfo seems to be missing from the latest release

any chance of getting it added back in?

`/**

  • getCurrentUserInfo
  • @access public
  • @returns {promise}
    */
    function getCurrentUserInfo() {
    var fn_name = 'getCurrentUserInfo()';
    if (!OAUTHENTICATED) return Promise.reject(noOAuthError(fn_name));
    var path = URL + '/api/auth_user';
    var authOptions = _getAuthOptions();
    var req = Request.builder().withPath(path).withOAuth(authOptions).build();
    return _execute(oAuthGet, req);
    };
    `

Basic functionality

Hi there!
Great idea to create an API wrapper for goodreads!
Just wanted to ask, maybe I've missed it, but the wrapper doesn't seem to have a search books functionality does it...? If I want to search book by title or by ISBN for example... It doesn't allow to do something like that does it?

Help with using API

I'm learning AngularJS and am trying to figure out how to use your API. I'm used to having something like:

import { Module } from 'goodreads-api-node"

and then plugging in an import or provider in the below piece of code.

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],

Could you help me with this?

Many thanks,
Tessa

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.