ianperrin / MMM-Strava

A MagicMirror Module for your Strava data.
https://forum.magicmirror.builders/topic/457/mmm-strava?_=1616840157932
MIT License
51 stars 15 forks source link

Module shows empty Chart #17

Closed Joris1979 closed 6 years ago

Joris1979 commented 6 years ago

I’ve installed the Strava module, the data displays correcty in “table” mode. When I switch the mode to “Chart” the weekly chart is empy. No data is visible, only a empty graph.

Any suggestions?

ianperrin commented 6 years ago

@Joris1979 - are you still experiencing this issue? If so, can you post your config for the module (without the strava_id and access_token)?

Joris1979 commented 6 years ago

Yes,

Here is my config:

{
                module: 'MMM-Strava',
            position: 'top_right',
            header: 'STRAVA ACTIVITY',
                config: {           
                    strava_id: '######',
                    access_token: '######',
                    mode: 'chart',                        // Possible values "table", "chart"
                    activities: ['ride'],
            }
ianperrin commented 6 years ago

@Joris1979

Here's a few of things to try.

Firstly, check your config.json file for errors. It might just be a paste issue here, but your config above is missing a closing bracket:

{
  module: 'MMM-Strava',
  position: 'top_right',
  header: 'STRAVA ACTIVITY',
  config: {
    strava_id: '######',
    access_token: '######',
    mode: 'chart', // Possible values "table", "chart"
    activities: ['ride'],
  }
},

Once corrected, and using my id and token, this confit works for me.

Next up, if you change the mode from table to chart whilst the MagicMirror is running, you will need to restart the MagicMirror otherwise you get the loading issue

Finally, make sure the module (and the MagicMirror) are fully updated.

If the above don't work, can you post the output of the log file? (Again, make sure you delete any access_token values from the data). It should look something like this...

Starting MagicMirror: v2.3.1
Loading config ...
Loading module helpers ...
No helper found for module: alert.
Initializing new module helper ...
Module helper loaded: updatenotification
No helper found for module: clock.
Initializing new module helper ...
Module helper loaded: MMM-Strava
All module helpers loaded.
Starting server on port 8080 ... 
You're using a full whitelist configuration to allow for all IPs
Server started ...
Connecting socket for: updatenotification
Connecting socket for: MMM-Strava
Starting module: MMM-Strava
Sockets connected & modules started ...

Ready to go! Please point your browser to: http://localhost:8080
MMM-Strava received a notification: CONFIG
MMM-Strava is fetching athlete activity after 1523750400
2018-04-17T21:19:31.380Z Make request: /api/v3/athlete/activities?after=1523750400 (GET) accessToken=XXXXXXX
Joris1979 commented 6 years ago

Thank you for your reply. The closing brackets are still in my config file. That's should not be the problem.

my log:

magicmirror@2.2.2 start /home/pi/MagicMirror sh run-start.sh

Starting MagicMirror: v2.2.2
Loading config ...
Loading module helpers ...
Initializing new module helper ...
Module helper loaded: MMM-MyCalendar
Initializing new module helper ...
Module helper loaded: MMM-rainfc
Initializing new module helper ...
Module helper loaded: MMM-Strava
Initializing new module helper ...
Module helper loaded: newsfeed
All module helpers loaded.
Starting server on port 8080 ... 
Server started ...
Connecting socket for: MMM-MyCalendar
Starting node helper for: MMM-MyCalendar
Connecting socket for: MMM-rainfc
Connecting socket for: MMM-Strava
Starting module: MMM-Strava
Connecting socket for: newsfeed
Starting module: newsfeed
Sockets connected & modules started ...
Launching application.
MMM-Strava received a notification: CONFIG
MMM-Strava is fetching athlete activity after #######
2018-04-21T05:11:53.292Z Make request: /api/v3/athlete/activities?after=##### (GET) accessToken=#######
ianperrin commented 6 years ago

Hi @Joris1979

I have made some modifications to the develop branch which fixes one potential issue.

Could you try the following for me?

cd MagicMirror/modules/MMM-Strava git checkout develop

Then modify your module to include the new debug option

{
  module: 'MMM-Strava',
  position: 'top_right',
  header: 'STRAVA ACTIVITY',
  config: {
    strava_id: '######',
    access_token: '######',
    mode: 'chart',
    activities: ['ride'],
    debug: true
  }
},

Then restart your MagicMirror and post the output from the log (again removing any access tokens)?

ianperrin commented 6 years ago

@Joris1979 - were you able to test the develop branch? I think it may fix your problem but I’d like to confirm that before releasing the change more widely

Thanks

Joris1979 commented 6 years ago

Hi @ianperrin, I'm quite busy at the moment. I will test the modified module in a few days and let you! Thanks

ianperrin commented 6 years ago

No worries - glad you’re able to help.

Joris1979 commented 6 years ago

Same problem.... Here's my debug log

Starting MagicMirror: v2.3.1 Loading config ... Loading module helpers ... Initializing new module helper ... Module helper loaded: MMM-MyCalendar Initializing new module helper ... Module helper loaded: MMM-rainfc Initializing new module helper ... Module helper loaded: MMM-Strava Initializing new module helper ... Module helper loaded: newsfeed All module helpers loaded. Starting server on port 8080 ... Server started ... Connecting socket for: MMM-MyCalendar Starting node helper for: MMM-MyCalendar Connecting socket for: MMM-rainfc Connecting socket for: MMM-Strava Starting module: MMM-Strava Connecting socket for: newsfeed Starting module: newsfeed Sockets connected & modules started ... Launching application. MMM-Strava received a notification: CONFIG MMM-Strava is fetching athlete activity after ##### Make request: /api/v3/athlete/activities?after=##### (GET) MMM-Strava is fetching athlete activity after ##### Make request: /api/v3/athlete/activities?after=##### (GET) MMM-Strava is fetching athlete activity after ##### Make request: /api/v3/athlete/activities?after=##### (GET)

Joris1979 commented 6 years ago

This is the log after disabling all other modules

magicmirror@2.3.1 start /home/pi/MagicMirror sh run-start.sh

Starting MagicMirror: v2.3.1 Loading config ... Loading module helpers ... No helper found for module: clock. Initializing new module helper ... Module helper loaded: MMM-Strava All module helpers loaded. Starting server on port 8080 ... Server started ... Connecting socket for: MMM-Strava Starting module: MMM-Strava Sockets connected & modules started ... Launching application. MMM-Strava received a notification: CONFIG MMM-Strava is fetching athlete activity after #### Make request: /api/v3/athlete/activities?after=#### (GET)

ianperrin commented 6 years ago

Ah sorry - you might need to pull the changes too - git pull from the MMM-Strava directory

Joris1979 commented 6 years ago

Same result.... 0 km.

First test with "table" mode: no problems. here's te log:

Starting MagicMirror: v2.3.1 Loading config ... Loading module helpers ... No helper found for module: clock. Initializing new module helper ... Module helper loaded: MMM-Strava All module helpers loaded. Starting server on port 8080 ... Server started ... Connecting socket for: MMM-Strava Starting module: MMM-Strava Sockets connected & modules started ... Launching application. MMM-Strava received a notification: CONFIG MMM-Strava is fetching athlete stats 2018-05-05T19:04:53.307Z Make request: /api/v3/athletes/####/stats (GET) accessToken=#################

Second test "chart" with no results...... I see there's no strava-id in the log when switching to chart mode.

Starting MagicMirror: v2.3.1 Loading config ... Loading module helpers ... No helper found for module: clock. Initializing new module helper ... Module helper loaded: MMM-Strava All module helpers loaded. Starting server on port 8080 ... Server started ... Connecting socket for: MMM-Strava Starting module: MMM-Strava Sockets connected & modules started ... Launching application. MMM-Strava received a notification: CONFIG MMM-Strava is fetching athlete activity after 1525039200 2018-05-05T19:05:50.845Z Make request: /api/v3/athlete/activities?after=1525039200 (GET) accessToken=####################

ianperrin commented 6 years ago

Hmm. I still looks like you’re not seeing the latest code from the develop branch as each line in the log should now be prefixed with MMM-Strava and the access_token is no longer written to the log

Can you try this

cd MagicMirror/modules/MMM-Strava
git reset --hard
git checkout -b develop origin/develop
Joris1979 commented 6 years ago

strange.... this is the log file. and still no results in chart-view.

Starting MagicMirror: v2.3.1 Loading config ... Loading module helpers ... No helper found for module: clock. Initializing new module helper ... Module helper loaded: MMM-Strava All module helpers loaded. Starting server on port 8080 ... Server started ... Connecting socket for: MMM-Strava Starting module: MMM-Strava Sockets connected & modules started ... Launching application. MMM-Strava: Fetching athlete activity after 1525039200 MMM-Strava: Make request: /api/v3/athlete/activities?after=1525039200 (GET) MMM-Strava: []

ianperrin commented 6 years ago

Okay, so youve picked up the changes.

MMM-Strava: [] suggests the API is returning no results for the last 7 days. Is it possible this is the case?

Joris1979 commented 6 years ago

That's impossible. 4 rides last week.

Can you provide me the right API settings for Strava? so i can check my setting in my Strava API dashboard.

ianperrin commented 6 years ago

Okay nevermind - it was a long shot.

If table mode is returning data, but chart isn’t then that suggests the token and id are correct. In the current develop branch the response from the API is output to the log. So if you switch to table mode you will see raw data in the output to confirm this.

In table mode the module calls https://www.strava.com/api/v3/athletes/{athleteId}/stats - where the athlete id equates to the strava id in the config

In chart mode the module calls https://www.strava.com/api/v3/athletes/activities?after={unixtimestamp} - where the after parameter is set to the beginning of the current week

Let me know if you find anything

Joris1979 commented 6 years ago

I've found the problem. All my activities are "private"

When I change the last ride to non private the chart is showing this.

Is there a way to show the private activities with the API?

ianperrin commented 6 years ago

Looks like you've found it.

Can you follow the steps on this page to generate a new access_token and report back?

Joris1979 commented 6 years ago

I know what I should do…..I can’t fix it. To retrieve the new token, i need some serious programming skills. I think.

Please let me know if the is another way to set the permission to “view_private”.

Van: Ian Verzonden: Monday, 7 May 2018 08:25 Aan: ianperrin/MMM-Strava CC: Joris1979; Mention Onderwerp: Re: [ianperrin/MMM-Strava] Module shows empty Chart (#17)

Looks like you've found it. Can you follow the steps on this page to generate a new access_token and report back? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ianperrin commented 6 years ago

Hi @Joris1979 - that's the only method I know of at the moment - but I'll keep looking.

In the meantime, if you're feeling up for the challenge, does this help

  1. Using a browser on your computer, go to the My API Application page in your Strava profile
  2. On the My API Application page, locate and make a note of your Client ID and Client Secret (you will need to click the show link to reveal the client secret).
  3. Using the Client ID obtained in step 2, replace XXXXX in the following URL: http://www.strava.com/oauth/authorize?client_id=XXXXX&response_type=code&redirect_uri=http://localhost/exchange_token&approval_prompt=force&scope=view_private then go to the URL in a browser on your computer
  4. If prompted, login, then Authorize the request
  5. You will then be redirected to and error (404) page. This is expected so don't panic. Copy the authentication code from the browsers address bar. The address will look something like http://localhost/exchange_token?state=&code=c498932e64136c8991a3fb31e3d1dfdf2f859357 - you need everything after code=
  6. Using the client id and client secret obtained in step 2 above and the code obtained in step 5, replace the respective values in the following command curl -X POST https://www.strava.com/oauth/token -F client_id=XXXXX -F client_secret=YYYYY -F code=ZZZZZ
  7. Using terminal on the Pi or via SSH, run the command
  8. Copy the access_token from the result and use it to update the module configuration in the config.js file

Hope this helps

Joris1979 commented 6 years ago

Solved…. Your step-by-step tutorial was very helpfull. Many thanks for the support!

Van: Ian Verzonden: Thursday, 10 May 2018 18:06 Aan: ianperrin/MMM-Strava CC: Joris1979; Mention Onderwerp: Re: [ianperrin/MMM-Strava] Module shows empty Chart (#17)

Hi @Joris1979 - that's the only method I know of at the moment - but I'll keep looking. In the meantime, if you're feeling up for the challenge, does this help

  1. Using a browser on your computer, go to the My API Application page in your Strava profile
  2. On the My API Application page, locate and make a note of your Client ID and Client Secret (you will need to click the show link to reveal the client secret).
  3. Using the Client ID obtained in step 2, replace XXXXX in the following URL: http://www.strava.com/oauth/authorize?client_id=XXXXX&response_type=code&redirect_uri=http://localhost/exchange_token&approval_prompt=force&scope=view_private then go to the URL in a browser on your computer
  4. If prompted, login, then Authorize the request
  5. You will then be redirected to and error (404) page. This is expected so don't panic. Copy the authentication code from the browsers address bar. The address will look something like http://localhost/exchange_token?state=&code=c498932e64136c8991a3fb31e3d1dfdf2f859357 - you need everything after code=
  6. Using the client id and client secret obtained in step 2 above and the code obtained in step 5, replace the respective values in the following command curl -X POST https://www.strava.com/oauth/token -F client_id=XXXXX -F client_secret=YYYYY -F code=ZZZZZ
  7. Using terminal on the Pi or via SSH, run the command
  8. Copy the access_token from the result and use it to update the module configuration in the config.js file Hope this helps — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.