Zapier JS Action 获取 Klout 分数
Zapier JS Action to Fetch Klout Scores
我正在尝试在 Zapier 上创建一个 Java 脚本代码操作来获取任何给定 Twitter 用户名的 Klout 分数...
我意识到这需要分两个阶段完成:
1) 首先获取任何 Twitter 的 Klout ID screen_name:
http://api.klout.com/v2/identity.json/twitter?screenName="+screen_name+"&key="+klout_apikey"
Klout 回复 JSon:
{"id":"85568398087870011","network":"ks"}
2) 其次获取该 Klout id 的 Klout 分数:
http://api.klout.com/v2/user.json/"+klout.id+"/score?key="+klout_apikey"
Klout 回复此 JSon:
{"score":65.68382904221806,"scoreDelta":{"dayChange":-0.03663891859041257,"weekChange":-0.5495711661078815,"monthChange":-1.4045672671990417},"bucket":"60-69"}
当然,我需要的是"score":65.68382904221806对象JSon回复数组
我使用了@KayCee 提出的以下 JS 函数:
var klout_apikey = '<my klout api key>';
fetch("http://api.klout.com/v2/identity.json/twitter?screenName="+screen_name+"&key="+klout_apikey")
.then(function(res) {
return res.json();
})
.then(function(klout) {
console.log(klout);
if(klout.id) {
return fetch("http://api.klout.com/v2/user.json/"+klout.id+"/score?key="+klout_apikey")
}
}).then(function(res) {
return res.json();
}).then(function(body) {
// console.log(body.score);
//Here is where you are telling Zapier what you want to output.
callback(null, body.score)
}).catch(callback); //Required by Zapier for all asynchronous functions.
在 Zapier 代码操作的 "input data" 部分,我将 screen_name 作为变量传递:
screen_name: [the twitter handle]
我得到的是以下错误信息:
SyntaxError: Invalid or unexpected token
您看到的错误是什么?您只需使用 fetch
客户端即可完成此操作。您可能希望在将其添加到代码步骤之前删除变量声明。
var inputData = {'screen_name': 'jtimberlake'}
//Remove the line above before pasting in the Code step. You will need to configure it in the Zap.
var klout_apikey = '2gm5rt3hsdsdrzgvnskmgm'; //Not a real key
fetch("http://api.klout.com/v2/identity.json/twitter?screenName="+inputData.screen_name+"&key="+klout_apikey)
.then(function(res) {
return res.json();
})
.then(function(body) {
console.log(body);
if(body.id) {
return fetch("http://api.klout.com/v2/user.json/"+body.id+"/score?key="+klout_apikey)
}
}).then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
//Here is where you are telling Zapier what you want to output.
callback(null, body)
}).catch(callback); //Required by Zapier for all asynchronous functions.
在此处参阅他们的文档 - https://zapier.com/help/code/#introductory-http-example
另请参阅他们的 Store
客户端,它允许您存储值(用于缓存)- https://zapier.com/help/code/#storeclient-javascript
我正在尝试在 Zapier 上创建一个 Java 脚本代码操作来获取任何给定 Twitter 用户名的 Klout 分数...
我意识到这需要分两个阶段完成:
1) 首先获取任何 Twitter 的 Klout ID screen_name:
http://api.klout.com/v2/identity.json/twitter?screenName="+screen_name+"&key="+klout_apikey"
Klout 回复 JSon:
{"id":"85568398087870011","network":"ks"}
2) 其次获取该 Klout id 的 Klout 分数:
http://api.klout.com/v2/user.json/"+klout.id+"/score?key="+klout_apikey"
Klout 回复此 JSon:
{"score":65.68382904221806,"scoreDelta":{"dayChange":-0.03663891859041257,"weekChange":-0.5495711661078815,"monthChange":-1.4045672671990417},"bucket":"60-69"}
当然,我需要的是"score":65.68382904221806对象JSon回复数组
我使用了@KayCee 提出的以下 JS 函数:
var klout_apikey = '<my klout api key>';
fetch("http://api.klout.com/v2/identity.json/twitter?screenName="+screen_name+"&key="+klout_apikey")
.then(function(res) {
return res.json();
})
.then(function(klout) {
console.log(klout);
if(klout.id) {
return fetch("http://api.klout.com/v2/user.json/"+klout.id+"/score?key="+klout_apikey")
}
}).then(function(res) {
return res.json();
}).then(function(body) {
// console.log(body.score);
//Here is where you are telling Zapier what you want to output.
callback(null, body.score)
}).catch(callback); //Required by Zapier for all asynchronous functions.
在 Zapier 代码操作的 "input data" 部分,我将 screen_name 作为变量传递:
screen_name: [the twitter handle]
我得到的是以下错误信息:
SyntaxError: Invalid or unexpected token
您看到的错误是什么?您只需使用 fetch
客户端即可完成此操作。您可能希望在将其添加到代码步骤之前删除变量声明。
var inputData = {'screen_name': 'jtimberlake'}
//Remove the line above before pasting in the Code step. You will need to configure it in the Zap.
var klout_apikey = '2gm5rt3hsdsdrzgvnskmgm'; //Not a real key
fetch("http://api.klout.com/v2/identity.json/twitter?screenName="+inputData.screen_name+"&key="+klout_apikey)
.then(function(res) {
return res.json();
})
.then(function(body) {
console.log(body);
if(body.id) {
return fetch("http://api.klout.com/v2/user.json/"+body.id+"/score?key="+klout_apikey)
}
}).then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
//Here is where you are telling Zapier what you want to output.
callback(null, body)
}).catch(callback); //Required by Zapier for all asynchronous functions.
在此处参阅他们的文档 - https://zapier.com/help/code/#introductory-http-example
另请参阅他们的 Store
客户端,它允许您存储值(用于缓存)- https://zapier.com/help/code/#storeclient-javascript