【发布时间】:2016-02-16 19:21:55
【问题描述】:
嘿,我正在尝试在 PHP 中使用 LinkedIn 的 OAuth。我被困在获取请求令牌的第一步。我所知道的是您将一些值发布到他们的服务器并取回您的令牌。所以我将记录在案的 args 发布到“https://api.linkedin.com/uas/oauth/requestToken”,然后我遇到了 400 错误。
这是请求:
$postArr = array();
//$postArr["oauth_callback"] = ""; idk they said this was optional...
$postArr["oauth_consumer_key"] = "ForBritishEyesOnly"; //is this the application secret key or the api key?
$postArr["oauth_nonce"] = "UltraRandomNonceFTW";
$postArr["oauth_timestamp"] = time();
$postArr["oauth_signature_method"] = "HMAC-SHA1"; //lolwut
$postArr["oauth_version"] = "1.0";
$params = array('http'=>array('method'=>'post','content'=>http_build_query($postArr)));
$context = stream_context_create($params);
$stream = file_get_contents('https://api.linkedin.com/uas/oauth/requestToken', false, $context);
我认为我的 POST 参数不正确,但非常感谢任何帮助——我只是不想求助于使用别人的库来解决这个问题。
-------编辑:根据詹姆斯的输入尝试 2 ---------
好的,我在这里拨打您发送给我的测试链接。我实际上能够得到回复,但它不喜欢我的签名(我知道,我很惊讶)。那么我把加密搞砸了到底有多糟糕?
//setup GET args
$url = "http://term.ie/oauth/example/request_token.php?";
$url .= "oauth_version=1.0&";
$url .= "oauth_nonce=" . rand(0, 100000) . "&";
$url .= "oauth_timestamp=" . time() . "&";
$url .= "oauth_consumer_key=key&";
$url .= "oauth_signature_method=HMAC-SHA1&";
//encrypt the request according to 'secret'
$sig = urlencode(base64_encode(hash_hmac("sha1", $url, "secret")));
//append the url encoded signature as the final GET arg
$url .= "oauth_signature=" . $sig;
//do it to it
echo file_get_contents($url);
詹姆斯编辑
试试:
//setup GET args
$url = "http://term.ie/oauth/example/request_token.php?";
$url .= "oauth_consumer_key=key&";
$url .= "oauth_nonce=" . rand(0, 100000) . "&";
$url .= "oauth_signature_method=HMAC-SHA1&";
$url .= "oauth_timestamp=" . time() . "&";
$url .= "oauth_version=1.0&";
【问题讨论】: