HTTP request failed

Issue No. 226

Type

Bug

Status

Closed

Reported By

Ryan Hudson-Peralta

Component

API

Resolution

Not a Bug

Votes

0

Created

5/Feb/16 11:08 AM EST

Closed

5/Feb/2016 12:10 PM EST

Description

I have had this working for months but now am getting the below errors. Code here: https://gist.github.com/hudsonperalta/b04f9af4d19a7829c85a Warning: fopen(): HTTP request failed! HTTP/1.1 401 Unauthorized in /Users/rperalta/Documents/Repos/prototypes/nba-snapshot/scores.php on line 62 Warning: fopen(compress.zlib://https://erikberg.com/events.json?sport=nba&date=20160204): failed to open stream: operation failed in /Users/rperalta/Documents/Repos/prototypes/nba-snapshot/scores.php on line 62 Warning: file_get_contents(public/scores.json): failed to open stream: No such file or directory in /Users/rperalta/Documents/Repos/prototypes/nba-snapshot/scores.php on line 113 Warning: Invalid argument supplied for foreach() in /Users/rperalta/Documents/Repos/prototypes/nba-snapshot/scores.php on line 119

Closing Comment

Yes, tokens expire after 30 days for a number of reasons. Recommend using the Me method (https://erikberg.com/api/methods/me) to alert when expiration is near. A daily cron job that executes a small script similar to the following is one way to do it: #!/bin/bash TOKEN="xxxx-xxx-xxx-xxxxx" seconds=$(curl -s \ -A "user@example.com" \ -H "Authorization: bearer $TOKEN" \ https://erikberg.com/me.json | \ sed -n '/token_expiration_seconds/s/[^0-9]//gp') if (( $seconds < 172800 )) then echo "Action needed! Token expires in less than 2 days ($seconds)." else echo "Token expires in" $(( $seconds/86400 )) "days." fi

Comments

1. Ryan Hudson-Peralta 5/Feb/2016 at 11:08 AM EST

You can see it live at http://nba.turnmatic.com/scores.php

2. Ryan Hudson-Peralta 5/Feb/2016 at 11:51 AM EST

CLOSE - I'm an idiot, forgot that the token expires