PHP oauth for linkedin

Joh*_*ohn 2 php oauth linkedin

我正在试用来自linkedin的快速入门指南进行oauth身份验证.我已经安装了oauth库.当我运行下面的代码时,我没有得到任何输出// ask for the pin.当我这样做时echo STDIN,浏览器实际上呈现STDIN而不是STDIN的值.为什么我没有看到输入引脚的字段,如快速入门指南中的链接所述?

这是快速入门指南中的代码.我用自己的API替换了API密钥.

<?php

// TODO change these to your API key and secret
define("API_CONSUMER_KEY", "xxxxxxxxxxxx");
define("API_CONSUMER_SECRET", "xxxxxxxxxxxx");

// create a new instance of the OAuth PECL extension class
$oauth = new OAuth(API_CONSUMER_KEY, API_CONSUMER_SECRET);

// get our request token
$api_url = "https://api.linkedin.com/uas/oauth/requestToken";
$rt_info = $oauth->getRequestToken($api_url);

// now set the token so we can get our access token
$oauth->setToken($rt_info["oauth_token"], $rt_info["oauth_token_secret"]);

// instruct on how to authorize the app
print("Please visit this URL:\n\n");
printf("https://www.linkedin.com/uas/oauth/authenticate?oauth_token=%s", $rt_info["oauth_token"]);
print("\n\nIn your browser and then input the numerical code you are provided here: ");

// ask for the pin  
$pin = trim(fgets(STDIN));

// get the access token now that we have the verifier pin
$at_info = $oauth->getAccessToken("https://api.linkedin.com/uas/oauth/accessToken", "", $pin);

// set the access token so we can make authenticated requests
$oauth->setToken($at_info["oauth_token"], $at_info["oauth_token_secret"]);

// do a simple query to make sure our token works
// we fetch our own profile on linkedin. This query will be explained more on later pages
$api_url = "http://api.linkedin.com/v1/people/~";
$oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET);

// print_response is just a fancy wrapper around print and is defined later
// or you can look now and see it in the code download
print_response($oauth);
Run Code Online (Sandbox Code Playgroud)

Jes*_*ose 5

我猜你正在运行一个PHP脚本,用于php myscript.php 服务器上下文中的终端(在终端中执行).并且服务器上下文不允许从STDIN读取.

编写一个新的PHP文件,$pin = "PIN I got from that URL"从提供的脚本开始,然后运行该脚本.并且,当心print_response 功能,我不知道他们的意思:-)

在您的示例中,LinkedIn在该网页中显示令牌.这称为带外访问,对于不做重定向的设备很有用,比如旧智能手机(AFAIK!).在正常的工作流程中,将其配置为重定向到您的回调URL, mysite.com/oauth_client/authentication_success?token=TOKEN并让该URL处理其余的.