I'm trying to write and read to and from my Firestore database from a Ruby script, eventually from a Rails application.
It seems like a trivial task but when I run a test script inside IRB it won't let me write or read data.
I tried:
google-cloud-firestore
gemrequire 'google/cloud/firestore' # => true
# credentials
cred = Google::Cloud::Firestore::Credentials.new('<path/to/my/keyfile/key-projectname-etc.json>')
# => #<Google::Cloud::Firestore::Credentials:...>
# initialize firestore connection
db = Google::Cloud::Firestore.new(
project_id: '<MY-PROJECT-ID>',
credentials: cred
) # => #<Google::Cloud::Firestore::Client:...>
# write a document inside the users collection
db.doc("users/helloFromRuby").set({ name: "yay it worked!"})
This is the error message I get:
Google::Cloud::UnavailableError (14:failed to connect to all addresses)
I could resolve my issue: I had an environmental variable GOOGLE_APPLICATION_CREDENTIALS
initialized that was somehow interfereing with my json keyfile. Deleting that variable solved my issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.