dblock / strava-ruby-client

A complete Ruby client for the Strava API v3.
https://code.dblock.org/2018/11/27/writing-a-new-strava-api-ruby-client.html
MIT License
97 stars 22 forks source link

Question: create_push_subscription parameters? #60

Closed interpegasus closed 2 years ago

interpegasus commented 2 years ago

Hello, I would like to know how to receive updates on new activities from all the users that authorized my app on Strava.

Do I need one web hook subscription for each user or just one global subscription for all users. Does create_push_subscription take any additional parameters? Thank you in advance.

Input

      callback_url = "https://[mydomain].com/api/strava_challenge"
      raise "Missing callback_url." unless callback_url
      webhook_client.logger.info "Subscribing to #{callback_url} ..."
      subscription = webhook_client.create_push_subscription(callback_url: callback_url, verify_token: "token")
      puts subscription.id

Output # subscription.id integer ID

interpegasus commented 2 years ago

One web-hook subscription is enough for all users. During web hook instantiation it uses the app credentials instead of the user client object generated from user permission.

    webhook_client = Strava::Webhooks::Client.new(
      client_id: Model::CLIENT_ID,
      client_secret: Model::CLIENT_SECRET,
      logger: logger,
    )

The response from Strava via a POST on the callback_url will include the owner_id which can be used to associate the corresponding user.

dblock commented 2 years ago

Please do update the README if you think this could be helpful to the next person!

datachomp commented 2 years ago

I'm a random user and I had not even thought about or considered this approach until this issue was created. Thank you both for the discussion and a new approach to try :)