google-api-python-client icon indicating copy to clipboard operation
google-api-python-client copied to clipboard

The BooksAPI.cloudloading methods no longer seem to work

Open varoOP opened this issue 1 year ago • 3 comments

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.

varoOP avatar Sep 06 '24 02:09 varoOP

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?

iblogbox avatar Sep 28 '24 10:09 iblogbox

I see that this issue has been labelled as a question. I am willing to provide any other relevant information required to solve this. Please let me know what is required

varoOP avatar Jan 12 '25 12:01 varoOP

I guess this api is ended. maybe experimental. https://issuetracker.google.com/issues/371142255

iblogbox avatar Jan 12 '25 12:01 iblogbox