mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-06 20:05:40 +01:00
add raw responses
This commit is contained in:
parent
2fb4660f5e
commit
05bea0e95d
@ -76,6 +76,12 @@ For all endpoints, response is reconstructed in the same format:
|
||||
}]
|
||||
```
|
||||
|
||||
If you want to get the original response returned from YouTube API, append `/raw` at the end of your request, e.g.:
|
||||
|
||||
```
|
||||
https://TASK_URL/TASK_NAME/playlist/:youtube_playlist_id/raw
|
||||
```
|
||||
|
||||
### Bounties
|
||||
|
||||
**`webtask-bounties.js`**: Task to fetch open bounties on Gitcoin and Bounties.network in one request. Task creates a unified response from fetching both networks.
|
||||
|
@ -20,7 +20,7 @@ const makeRequest = (options, cb) => {
|
||||
}
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Please specify the playlist ID as parameter.')
|
||||
res.send('Please use /channel or /playlist endpoints, appended with the channel or playlist ID as parameter.')
|
||||
})
|
||||
|
||||
app.get('/channel/:channelId', (req, res) => {
|
||||
@ -47,6 +47,17 @@ app.get('/channel/:channelId', (req, res) => {
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/channel/:channelId/raw', (req, res) => {
|
||||
const options = {
|
||||
url: `https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${req.params.channelId}&maxResults=10&order=date&type=video&key=${req.webtaskContext.secrets.YOUTUBE_API_KEY}`,
|
||||
headers: { 'referer': req.headers.host }
|
||||
}
|
||||
|
||||
makeRequest(options, (videos) => {
|
||||
res.send(videos)
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/playlist/:playlistId', (req, res) => {
|
||||
const options = {
|
||||
url: `https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=10&playlistId=${req.params.playlistID}&key=${req.webtaskContext.secrets.YOUTUBE_API_KEY}`,
|
||||
@ -73,18 +84,12 @@ app.get('/playlist/:playlistId', (req, res) => {
|
||||
|
||||
app.get('/playlist/:playlist/raw', (req, res) => {
|
||||
const options = {
|
||||
url: `https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&playlistId=${req.params.playlist}&key=${process.env.YOUTUBE_API_KEY}`,
|
||||
url: `https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=10&playlistId=${req.params.playlist}&key=${process.env.YOUTUBE_API_KEY}`,
|
||||
headers: { 'referer': req.headers.host }
|
||||
}
|
||||
|
||||
request(options, (error, response, body) => {
|
||||
const json = JSON.parse(body)
|
||||
|
||||
if (error) {
|
||||
return
|
||||
}
|
||||
|
||||
res.send(json.items)
|
||||
makeRequest(options, (videos) => {
|
||||
res.send(videos)
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user