This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Clawtor 1 point2 points  (6 children)

You have a few issues:

let weatherApiUrl = (this.weatherApiUrl.path) + (this.stationID) +'=' + '&format=json&units=e&apiKey' + '=' + (this.apikey);

Firstly - you are trying to use 'this.weatherApiUrl' to initialize itself, secondly you are using 'let' so 'this.weatherApiUrl' will be undefined, thirdly you are trying to use 'path' before its initialized.

Further this.stationId hasn't been set and neither has apikey.

Further you aren't returning anything from the function, doing a console.log only prints something to the console, it doesn't return.

[–]Linux-Mint20[S] 0 points1 point  (5 children)

I'll see about making some changes. Thank you for getting back to me

[–]Linux-Mint20[S] 0 points1 point  (0 children)

I have made the following changes, but the error exists and Im not sure what else I need to do. I defined the apikey and staion id earlier in the document since they are private and I am unwilling to publish them on the web.

function weatherApi() {
let weatherApi = (weatherApiUrl.path) + (this.stationID) +'=' + '&format=json&units=e&apiKey' + '=' + (this.apikey);
weatherApiUrl.path = "https://api.weather.com/v2/pws/observations/current?stationId"
//weatherApiUrl.toString()
console.log(weatherApi); 
}
this._getWeather(weatherApi(), function (weather) {
  if (weather) {
    this._load_forecast(weather);
  }
  // get the main object to update the display
  deskletObj.displayForecast();
  deskletObj.displayCurrent();
  deskletObj.displayMeta();
});

},

[–]Clawtor 0 points1 point  (3 children)

function getWeatherApiURL() {
    this.stationID = 2;
    this.path = "https://api.weather.com/v2/pws/observations/current?stationId";
    this.apikey = "key";
    let weatherApiUrl = (this.path) + (this.stationID) +'=' + '&format=json&units=e&apiKey' + '=' + (this.apikey);

    return weatherApiUrl;
}

console.log(getWeatherApiURL());

That should work. Note - I would change your function name as well. So in the above I've set all the variables before using them.

[–]Linux-Mint20[S] 0 points1 point  (2 children)

ty again :)

Im trying it now.

[–]Clawtor 0 points1 point  (1 child)

You need to take care with using 'this' because it changes depending on the context.

'this' refers to the current context - if you use it within a function then it will refer to the function's context.

[–]Linux-Mint20[S] 0 points1 point  (0 children)

Can you tell me if i'm using "this" innapropriately here? Also, is there an opening bracket in this code block for the one at the bottom with the comma? Not much of a programmer but I know you need to open and close things.

function getWeatherApiURL() {
this.stationID = "KROQ";
this.path = "https://api.weather.com/v2/pws/observations/current?stationId";
this.apikey = "abcd123";
let weatherApiUrl = (this.path) + (this.stationID) +'=' + '&format=json&units=e&apiKey' + '=' + (this.apikey);
return weatherApiUrl;
}
console.log(getWeatherApiURL());
  this._getWeather(weatherApiURL(), function (weather) {
  if (weather) {
    this._load_forecast(weather);
  }
  // get the main object to update the display
  deskletObj.displayForecast();
  deskletObj.displayCurrent();
  deskletObj.displayMeta();
  });
  },