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

The BooksAPI.cloudloading methods no longer seem to work #2477

Open
varoOP opened this issue Sep 6, 2024 · 1 comment
Open

The BooksAPI.cloudloading methods no longer seem to work #2477

varoOP opened this issue Sep 6, 2024 · 1 comment
Labels
type: question Request for information or clarification. Not an issue.

Comments

@varoOP
Copy link

varoOP commented Sep 6, 2024

Environment details

  • OS type and version: Debian 11
  • Python version: Python 3.9.2
  • pip version: pip 20.3.4
  • google-api-python-client version: 2.141.0

Steps to reproduce

  1. Get oauth 2.0 token with offline access for the following scope: "https://www.googleapis.com/auth/books"
  2. Confirm it works to access user data at the following API end-point: https://www.googleapis.com/books/v1/mylibrary/bookshelves
  3. Try adding a book with the following end-point: https://books.googleapis.com/books/v1/cloudloading/addBook
  4. Get a 401 error, although the token is valid.

Code example

from googleapiclient.discovery import build
import google.auth.transport.requests as refresh
from google.oauth2.credentials import Credentials
import sys

id=sys.argv[1]

def upload_epub_to_play_books():
    # Load the OAuth 2.0 credentials from a file
    creds = Credentials.from_authorized_user_file('/home/user/scripts/playbooks/credentials.json')

    # if not creds.valid:
    #     if creds.refresh_token:
    #         request = refresh.Request()
    #         creds.refresh(request)

    #     if creds.valid:
    #         print("Creds valid and were refreshed")
    #         with open('/home/user/scripts/playbooks/credentials.json', 'w') as token:
    #             token.write(creds.to_json())
    # else:
    #     print("creds already valid")

    # Create a Google Play Books API service client
    service = build('books', 'v1', credentials=creds)

    # Upload the epub file to Google Play Books
    response = service.cloudloading().addBook(drive_document_id=id).execute()
    print(response)


# Upload an epub file to Google Play Books
upload_epub_to_play_books()

Stack trace

Traceback (most recent call last):
  File "/home/user/scripts/playbooks/add_to_playbooks.py", line 33, in <module>
    upload_epub_to_play_books()
  File "/home/user/scripts/playbooks/add_to_playbooks.py", line 28, in upload_epub_to_play_books
    response = service.cloudloading().addBook(drive_document_id=id).execute()
  File "/home/user/.local/lib/python3.9/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/user/.local/lib/python3.9/site-packages/googleapiclient/http.py", line 938, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 401 when requesting https://books.googleapis.com/books/v1/cloudloading/addBook?drive_document_id=1QBcMAaQktHT-LmqKDM90ub0XL3IRzBNW&alt=json returned "Invalid Credentials". Details: "[{'message': 'Invalid Credentials', 'domain': 'global', 'reason': 'authError', 'location': 'Authorization', 'locationType': 'header'}]">

This is really strange, because the script was working just a few months ago. It suddenly stopped working and giving 401 errors. I am 100% confident that the credentials/token are not invalid.

@vchudnov-g vchudnov-g added the type: question Request for information or clarification. Not an issue. label Sep 23, 2024
@iblogbox
Copy link

https://content.googleapis.com/books/v1/cloudloading/addBook?drive_document_id=xxxxxxxxxx....
me too, It's not work. "404 Invalid Credentials" error. this api is deprecated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

4 participants