-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Twitch clips to Helix API (#144)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
- Loading branch information
Showing
8 changed files
with
147 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package twitch | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/nicklaw5/helix" | ||
) | ||
|
||
// initAppAccessToken requests and sets app access token to the provided helix.Client | ||
// and initializes a ticker running every 24 Hours which re-requests and sets app access token | ||
func initAppAccessToken(helixAPI *helix.Client, tokenFetched chan struct{}) { | ||
response, err := helixAPI.RequestAppAccessToken([]string{}) | ||
|
||
if err != nil { | ||
log.Fatalf("[Helix] Error requesting app access token: %s , \n %s", err.Error(), response.Error) | ||
} | ||
|
||
log.Printf("[Helix] Requested access token, status: %d, expires in: %d", response.StatusCode, response.Data.ExpiresIn) | ||
helixAPI.SetAppAccessToken(response.Data.AccessToken) | ||
close(tokenFetched) | ||
|
||
// initialize the ticker | ||
ticker := time.NewTicker(24 * time.Hour) | ||
|
||
for range ticker.C { | ||
response, err := helixAPI.RequestAppAccessToken([]string{}) | ||
if err != nil { | ||
log.Printf("[Helix] Failed to re-request app access token from ticker, status: %d", response.StatusCode) | ||
continue | ||
} | ||
log.Printf("[Helix] Re-requested access token from ticker, status: %d, expires in: %d", response.StatusCode, response.Data.ExpiresIn) | ||
|
||
helixAPI.SetAppAccessToken(response.Data.AccessToken) | ||
} | ||
} |