通过 API 将用户添加到跑道工作区

问题描述

我们正在使用 Podio API 将我们的解决方案安装到客户的组织中(工作区、应用程序、挂钩、视图、网络挂钩等)。我们需要将自己添加到这个新工作区

示例代码如下。希望这有助于任何人学习如何通过服务器进行身份验证。

我们从跑道管理员那里获得了 2 级信任,以下代码适用于运行 xampp 的 Windows 10 本地主机,但不适用于服务器。

在服务器上,此代码返回:“仅适用于信任级别为 2 或更高的客户端。要让您的 API 客户端升级到更高的信任级别,请在 https://help.podio.com 上联系支持人员。”

混淆代码的结构:

  • 如果我们以自己的身份进行身份验证,给予我们 2 级信任,我们就无权将用户添加到其他人的空间。
  • 如果我们以他们的身份进行身份验证,我们就没有 2 级(在服务器上,我们有 显然是在运行 xampp 的 Windows 10 本地主机上)。

有人知道如何解决这个问题吗?

<?PHP

require __DIR__ . '/../vendor/autoload.PHP';
include 'constants.PHP';
// to use this file
// - update constants.PHP with POdio_CLIENTID and POdio_CLIENTSECRET,SERVER_URL
//   - define('POdio_CLIENTID','');
//   - define('POdio_CLIENTSECRET','');
//   - define('SERVER_URL',''); // requires trailing backslash: ex: https://localhost/

// - set REDIRECT_URI
// - set MEMBER_ORG_ID,MEMBER_SPACE_ID,and ADMIN_USER_ID
// - localhost call: http://localhost/podio_laravel/public/PodioMembership.PHP
// - dev.noterules.com call: https://dev.noterules.com/PodioMembership.PHP

define("REDIRECT_URI",SERVER_URL . 'PodioMembership.PHP');

member();

// authenticate as user,add admin
function member() {
    $client_id=POdio_CLIENTID;
    $client_secret=POdio_CLIENTSECRET;
    Podio::setup($client_id,$client_secret);

    $org_id = MEMBER_ORG_ID;
    $space_id = MEMBER_SPACE_ID;
    $admin_user = ADMIN_USER_ID;
    $attributes = ['role' => 'admin','users' => array($admin_user)];

    if (Podio::is_authenticated()) {
        print 'is authenticated,doing nothing';
    } elseif (!isset($_GET['code'])) {
        $auth_url = htmlentities(Podio::authorize_url(REDIRECT_URI,'global:all'));
        print "<a href='{$auth_url}'>Start authenticating</a>";
    } else {
        if (!isset($_GET['error'])) {
            $response = authenticate_with_code($_GET['code']);
            if (!$response['hasError']) {
                print 'authenticated with code<br>';

                $response = add_member($space_id,$attributes);
                if(!$response['hasError']) {
                    print 'add_member success';
                } else {
                    print 'add_member response: ' . $response['message'];
                }
            } else {
                print 'authentication response: ' . $response['message'];
            }
        } else {
            print "There was a problem. The server said: {$_GET['error_description']}<br>";
        }
    }
}

function add_member($space_id,$attributes) {
    try {
        $data = PodioSpaceMember::add($space_id,$attributes);
        return [
            'hasError' => false,'data' => $data
        ];
    } catch (PodioError $ex) {
        return [
            'hasError' => true,'error' => $ex,'message' => $ex->body['error_description']
        ];
    }
}

function authenticate_with_code($code) {
    try {
        $response = Podio::authenticate('authorization_code',array('code' => $code,'redirect_uri' => REDIRECT_URI));
        return [
            'hasError' => false,'data' => $response
        ];
    } catch (PodioError $ex) {
        return [
            'hasError' => true,'message' => $ex->body['error_description'],'error' => $ex
        ];
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...