0

I am trying to Update Cover Photo of Google My Business in Flask App. Below is my code to achieve the same.

SCOPES = ["https://www.googleapis.com/auth/business.manage"]
API_SERVICE_NAME = "mybusiness"
API_VERSION = "v1"
API_KEY = "api-key-here"
CLIENT_SECRETS_FILE = "client_secret.json"
SCOPES = ["https://www.googleapis.com/auth/business.manage"]

gmb_app_verify_business_test.credentials = google.oauth2.credentials.Credentials(
    **flask.session["credentials"])

flask.session["credentials"] = modules.credentials_to_dict(
    gmb_app_verify_business_test.credentials)

service = googleapiclient.discovery.build(
    API_SERVICE_NAME,
    API_VERSION,
    credentials=credentials,
    developerKey=API_KEY,
    discoveryServiceUrl="https://mybusiness.googleapis.com/$discovery/rest?version=v1",
)

cover_update_status = (
    service.accounts()
    .locations()
    .media()
    .create(
        parent='accounts/xxxxxxxxxxxx/locations/xxxxxxxxxxxxxxxxxxxxxx',
        body={
            "name": "IFB Point Cover",
            "mediaFormat": "PHOTO",
            "locationAssociation": {
                "category": "COVER",
            },
            "sourceUrl": "https://www.ifbappliances.com/media/ifb/ifb-point-cover.png",
        },
    )
    .execute()
)

This is giving an error: googleapiclient.errors.UnknownApiNameOrVersion: name: mybusiness version: v1

I tried changing the version to API_VERSION to v4 and discoveryServiceUrl to v4. But the error persists.

Documentation Referred so far:

But nothing seems to work. Suggestions Please.

gm-123
  • 248
  • 3
  • 16

1 Answers1

0

You are almost there.

For API_VERSION, you need to set it to v4; because the mybusiness service is working on v4.

And for discoveryUrl, you need to pass it as following:

discoveryServiceUrl="https://developers.google.com/my-business/samples/mybusiness_google_rest_v4p9.json"
stuck
  • 1,477
  • 2
  • 14
  • 30