kiwiz / gkeepapi

An unofficial client for the Google Keep API.
MIT License
1.53k stars 114 forks source link

getMediaLink Dosen't seem to work #99

Closed rmetcalf9 closed 4 years ago

rmetcalf9 commented 4 years ago

I have what I thought would be very simple code. Just trying to list notes and get the url's to download the images:

import gkeepapi
from getpass import getpass
import os

keep = gkeepapi.Keep()
username = os.environ["GOOGLEKEEPUSERNAME"]
password = os.environ["GOOGLEKEEPAPPPASSWORD"]
success = keep.login(username, password)

gnotes = keep.all()

for note in gnotes:
    print("Title", note.title)
    for curImage in note.images:
      #print("ci", curImage.height, curImage.width)
      print("I", keep.getMediaLink(curImage))

But no luck.

Traceback (most recent call last):
  File "./main.py", line 22, in <module>
    print("I", keep.getMediaLink(curImage))
  File "/home/robert/.local/lib/python3.8/site-packages/gkeepapi/__init__.py", line 970, in getMediaLink
    return self._media_api.get(blob)
  File "/home/robert/.local/lib/python3.8/site-packages/gkeepapi/__init__.py", line 381, in get
    url = self._base_url + blob.parent.server_id + '/' + blob.server_id
AttributeError: 'NodeImage' object has no attribute 'parent'

I have searched the code for getMediaLink. I can't seem to find any test that covers this function. Also I can't understand where blob.parent.server_id and blog.server_id should come from.

My curImage object seems to be of type NodeImage This is derived from NodeBlob Which comes from Element

None of these objects have a refernece to self.parent, or self.server_id.

There is another class "class Node(Element, TimestampsMixin):" which does have both a self.parent and a self.server_id.

As an alternative method I have tried calling curImage.url but I get not implemented for this.

Does anyone have an example of the correct use of getMediaLink?

kiwiz commented 4 years ago

Thanks for opening this PR. This was due to a backwards incompatible change in the blobs interface. I've reverted it and pushed up a new version, so this should work again.

rmetcalf9 commented 4 years ago

New version works for me now. Thanks for the update!