2016-01-22 780 views
1

我需要访问infusionsoft api而无需用户交互。我不想让用户点击一下鼠标,这样我就可以得到一个答案。可能吗?infusionsoft - 如何获得令牌没有点击链接?

$infusionsoft = new Infusionsoft\Infusionsoft(array(
    'clientId'  => '...', 
    'clientSecret' => '...', 
    'redirectUri' => '...', 
)); 

// If the serialized token is available in the session storage, we tell the SDK 
// to use that token for subsequent requests. 
if (isset($_SESSION['token'])) { 
    $infusionsoft->setToken(unserialize($_SESSION['token'])); 
} 

// If we are returning from Infusionsoft we need to exchange the code for an 
// access token. 
if (isset($_GET['code']) and !$infusionsoft->getToken()) { 
    $infusionsoft->requestAccessToken($_GET['code']); 
} 

if ($infusionsoft->getToken()) { 
    // Save the serialized token to the current session for subsequent requests 
    $_SESSION['token'] = serialize($infusionsoft->getToken()); 

    // MAKE INFUSIONSOFT REQUEST 
} else { 
    echo '<a href="' . $infusionsoft->getAuthorizationUrl() . '">Click here to authorize</a>'; 
} 

回答

0

如果您正在寻找与API交互,并没有得到通过新的OAuth的方法访问,您将需要使用它使用一个API key from the actual Infusionsoft application折旧遗留API。好处是,除非用户更改其API密钥,否则不需要“续订”或“刷新”令牌,并且不需要用户单击通过授权他们的应用程序。

当然,最大的缺点是这个较旧的API已经折旧,所有新的应用程序都需要使用oAuth。

什么是您不能通过oAuth身份验证流程走过用户的用例?

+0

我处于同样的情况。我们的用例是我们需要检索我们的订单,以便我们可以通过我们自己的集中管理来管理它们。 – cyberwombat

0

制作3个文件

  1. Request_new_token.php。它与您的代码类似(只需运行一次),但您必须将令牌保存到数据库或txt文件。

    //Convert object to string 
    $token = serialize($infusionsoft->requestAccessToken($_GET['code'])); 
    //Update the token in database. 
    $update = new Update("systemsettings"); 
    $update->addColumn('systemsettings_strvalue', $token); 
    $update->run(1); 
    exit;  
    
  2. Refresh_token.php。使用保存的令牌,您需要在21小时内刷新它。我建议使用cronjob在服务器后端自动运行它。

  3. General_request.php(直到您的系统首选项)。无论何时您需要向GET/PUT/POST发出单一请求,您只需启动infusionsoft对象并将令牌设置为来自数据库的新对象。

祝你好运!