【问题标题】:Automating Linkedin oAuth usin Curl and PHP使用 Curl 和 PHP 自动化 Linkedin oAuth
【发布时间】:2010-11-16 00:24:39
【问题描述】:

我正在尝试自动化验证 LinkedIn 登录的过程,以便在 LinkedIn 上对人员执行公开搜索。

首先我会尝试解释我在做什么。

我正在使用四个文件:

  • oAuth.php(必填)
  • linkedin.php (php LinkedIn 库)
  • auth.php(从 LinkedIn lib 文件中获取 oAuth 令牌)
  • 回调 url demo.php?params(认证成功后,使用参数打印当前用户的个人资料和搜索结果)

认证地址为https://api.linkedin.com/uas/oauth/authorize?oauth_token=$oauthtoken

我做了两件事,似乎都没有用;他们是:

  1. 我正在使用 curl 自动执行访问身份验证 url、发布字段(用户名、密码、oauth 令牌、csrfToken、持续时间、sourceAlias 等,我从 Firebug 了解到)的过程。

    这里唯一改变的两件事是 oauth 令牌和 csrfToken(通过解析身份验证 url 中的内容)。每次页面加载时,我都能同时获得两者,最后尝试从 curl_exec 打印 GET 响应。

  2. 尝试仅发布电子邮件和密码,并尝试打印 GET 响应。

这里是我的auth.php供参考:

function extract_unit($string, $start, $end)
{
    $pos = stripos($string, $start);
    $str = substr($string, $pos);
    $str_two = substr($str, strlen($start));
    $second_pos = stripos($str_two, $end);
    $str_three = substr($str_two, 0, $second_pos);
    $unit = trim($str_three); // remove whitespaces
    return $unit;
}

session_start();

$config['base_url']             =   'http://linkedin.tweetrank.tk/auth.php';
$config['callback_url']         =   'http://linkedin.tweetrank.tk/demo.php';
$config['linkedin_access']      =   'my key';
$config['linkedin_secret']      =   'my secret';

include_once "linkedin.php";

# First step is to initialize with the consumer key and secret. We'll use
# an out-of-band oauth_callback
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url']);
//$linkedin->debug = true;

# Now we retrieve a request token. It will be set as $linkedin->request_token
$linkedin->getRequestToken();
$_SESSION['requestToken'] = serialize($linkedin->request_token);

# With a request token in hand, we can generate an authorization URL, which
# we'll direct the user to
//echo "Authorization URL: " . $linkedin->generateAuthorizeUrl() . "\n\n";

echo $url = $linkedin->generateAuthorizeUrl();
$token = $linkedin->generateAuthorizeToken();
//echo '<br><br>';
$data = file_get_contents($url);
$csrfToken = extract_unit($data,'name="csrfToken" value="','"');

//echo $csrfToken;
//echo $token;
//echo 'https://www.linkedin.com/uas/oauth/authenticate?oauth_token='.$token.'&amp;trk=uas-continue';
// INIT CURL

$postParams = 'email=myemail&password=mypassword&duration=720&authorize=Ok%2C+I%27ll+Allow+It&extra=&access=-3&agree=true&oauth_token='.$token.'&appId=&csrfToken='.$csrfToken.'&sourceAlias=0_8L1usXMS_e_-SfuxXa1idxJ207ESR8hAXKfus4aDeAk';

现在我使用了身份验证 URL 和带有 curl 的 postParams

【问题讨论】:

    标签: php oauth linkedin


    【解决方案1】:

    为了通过登录过程,必须使用linkedIn网页授权步骤;我们不可能让第三方应用程序接受凭据并使用链接https://api.linkedin.com/uas/oauth/authorize?oauth_token=$oauthtoken 进行linkedIn 授权

    【讨论】:

      【解决方案2】:

      我想我理解您的要求,答案是否定的,您无法通过 LinkedIn 做到这一点。我最近遇到了类似的问题,无法解决。我猜LinkedIn的家伙对数据保护和其他东西有很好的看法。 看一下这个: http://developer.linkedin.com/message/6460 http://getsatisfaction.com/linkedin/topics/cant_use_linkedin_api_to_view_public_profiles_without_oauth_login

      【讨论】:

        猜你喜欢
        • 2012-12-30
        • 2012-01-10
        • 1970-01-01
        • 1970-01-01
        • 2019-05-29
        • 2011-01-19
        • 2011-10-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多