1

我正在尝试获取用户对 TinyPass 资源的访问详细信息。

我刚刚开始尝试集成它并使用示例代码。

    $params = array();
    $params["rid"] =  $rid;
    $params["user_ref"] = $username;
    $result = TinyPass::fetchAccessDetails($params, 1, 200);
    echo $result->getTotal();

但是我在上面的行中收到了一个未捕获的异常 API 错误 ($result=...)

有没有人可以给我一些帮助?

PS:我正在尝试将我的自定义 PHP 站点的用户名发送到 tinypass,然后想获取该用户的数据。

这是我的代码

$rid = "PW_74296909";
$store = new TPAccessTokenStore();
$store->loadTokensFromCookie($_COOKIE);
$token = $store->getAccessToken($rid);
if($token->isAccessGranted()) {
    //Access granted! Display requested resource to the user
    echo 'WEELCOOOE';
} else {
    //Access denied! Proceed with the next steps and display a Tinypass button...

    $resource = new TPResource($rid, "Site wide premium content access");

    $po1 = new TPPriceOption(".50", "24 hours");
    $po2 = new TPPriceOption(".99", "1 week");
    $offer = new TPOffer($resource, array($po1, $po2));

    /*$request = new TPPurchaseRequest($offer);
    $buttonHTML = $request->setCallback("myFunction")->generateTag();

    //output button HTML in the place where Tinypass button is supposed to be rendered
    echo $buttonHTML;
    */

    //set user reference (username in this case)
    $username='member';


    $purchaseRequest = new TPPurchaseRequest($offer);
    $purchaseRequest->setUserRef($username);
    $link = $purchaseRequest->generateLink("http://localhost/Tinypass/index.php?action=success", "http://localhost/Tinypass/index.php?action=success");
    $buttonHTML= '<a href="'.$link.'" style="color:white; font-size:20px;">BUY IT</a>';

    //$buttonHTML = $purchaseRequest->setCallback("myFunction")->generateTag();
    echo $buttonHTML;

    $params = array();
    $params["rid"] =  $rid;
    $params["user_ref"] = $username;
    $result = TinyPass::fetchAccessDetails($params, 1, 200);
    echo $result->getTotal();
4

1 回答 1

1

也许您应该为此使用奇异函数:

$result = Tinypass:fetchaccessDetail(array('rid'=>$rid,'user_ref'=>$userref));
if ($result) {echo "<!-- "; print_r($result); echo " -->";}

如果您确实使用了复数函数,请尝试 getTotal 以外的其他方法:

$results = TinyPass::fetchAccessDetails($params, 1, 200);
if (count($results['data') > 0) {
    foreach ($results['data'] as $record) {
        echo "<!-- "; print_r($record); echo " -->";
    }
}

看起来它更像是您将需要的单数功能,它为您提供的信息比复数功能略多。http://developer.tinypass.com/main/restapi

如果一切正常,您应该返回一个数组,其中列出的值作为数组键。注意: fetchAccessDetails 仍然返回 'user_email' 而不是 API 页面建议的 'email'。

如果您仍然遇到麻烦(就像我一样),您可以做的另一件事是编辑 TinyPassGateway.php 文件,这些函数位于这些函数所在的位置以及之前行中的每个函数中:

throw $e;

添加:

return $e->getMessage;

因为您可以通过这种方式获得更直接的调试信息...

于 2014-11-12T10:52:52.537 回答