我是个用Slack编程斜杠命令的新手。对于我的一个命令,我有一个用户名,并且需要检索用户图标URL。我正在使用PHP对它们进行编码。
我计划使用users.profile.get,因为教程here显示返回的其中一个字段是用户图标URL。
但是,我正在尝试寻找有关如何调用此方法的示例,但尚未找到任何示例。谁能给我一个简单的调用示例,包括如何发送参数?
这就是我得到的结果:
$slack_profile_url = "https://slack.com/api/users.profile.get";
$fields = urlencode($data);
$slack_call = curl_init($slack_profile_url);
curl_setopt($slack_call, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($slack_call, CURLOPT_POSTFIELDS, $fields);
curl_setopt($slack_call, CURLOPT_CRLF, true);
curl_setopt($slack_call, CURLOPT_RETURNTRANSFER, true);
curl_setopt($slack_call, CURLOPT_HTTPHEADER, array(
"Content-Type: application/x-www-form-urlencoded",
"Content-Length: " . strlen($fields))
);
$profile = curl_exec($slack_call);
curl_close($slack_call);我基本上有$token和$user_name,并需要获得个人资料图片网址。如何将$token和$username格式化为$data?呼叫是否正确?
如果有人建议用不同的方式来做这件事,我也将非常感谢任何建议。
非常感谢!
发布于 2017-07-05 10:02:20
将数据转换为正确的格式以发布到Slack是非常简单的。有两个选项(POST body或application/x-www-form-urlencoded)。
application/x-www-form-urlencoded的查询字符串的格式类似于get URL字符串。
https://slack.com/api/users.profile.get?token={token}&user={user}
// Optionally you can add pretty=1 to make it more readable
https://slack.com/api/users.profile.get?token={token}&user={user}&pretty=1只需请求该URL,您就可以检索数据。
帖子正文格式将使用与上面类似的代码。
$loc = "https://slack.com/api/users.profile.get";
$POST['token'] = "{token}";
$POST['user'] = "{user}";
$ch = curl_init($loc);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $POST);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if ($error = curl_errno($ch)) { echo $error; }
//close connection
curl_close($ch);
echo $result;https://stackoverflow.com/questions/44897625
复制相似问题