【发布时间】:2018-10-11 11:36:07
【问题描述】:
我对 Podio PHP API 身份验证有疑问。如果没有以下致命错误,我将无法完成某些事情。我这样做:Podio::authenticate_with_password('aaa', 'bbb');
我明白了:PHP Fatal error: Uncaught PodioRateLimitError: "You have hit the rate limit. Please wait 300 seconds before trying again"
我的系统处理分布在许多空间中的复杂关系,这就是为什么我创建了一个“主”帐户,该帐户在每个目标空间中都具有管理员角色。
每次调用 webhook 时,我都会使用“主”帐户进行身份验证(由于同一脚本中存在多个关系,因此使用应用进行身份验证需要大量工作)。
同一个 webhook 被多次调用,但在不同的上下文中。
如何避免在每次调用我的 webhook 时破坏速率限制?我尝试了 OAuth 2,但 Podio 文档对我没有帮助。没有任何尝试对我有用。
您是否有任何方法将身份验证数据保存在内存/数据库中,以便能够将其用于来自多个 webhook 调用的每个 password 身份验证?
任何帮助将不胜感激!
解决方案
我在 Podio PHP API 类中发现了一些有趣的东西:
这就是我所做的:
// Set user API key
Podio::setup('user-key', 'wejt9wetwerith34rtfhwetu34hwerud);
// Init refresh_token variable (avoid PHP warning if any refresh_token found in database)
$refresh_token = null;
// Get refresh_token from database if exists
$refresh_token = REFRESH_TOKEN_FROM_DATABASE;
// Authenticate
try{
// Authenticate with refresh token stored in database
Podio::authenticate( 'refresh_token', array( 'refresh_token' => $refresh_token ) );
}
// Authentication failed, request new refresh_token
catch ( Exception $ex ) {
Podio::authenticate_with_password( 'aaa', 'bbb' );
// Get Oauth data including refresh token
$oauth = Podio::$oauth;
// Authenticate with refresh token
Podio::authenticate( 'refresh_token', array( 'refresh_token' => $oauth->refresh_token ) );
// Store $oauth->refresh_token in database for next webhook call...
}
非常重要在您的脚本中使用相同的用户 API 密钥以避免身份验证速率限制破坏,因为 refresh_token 链接到用于发出请求的用户 API 密钥。
【问题讨论】:
-
@hassanmaleki - 你的问题(你链接的那个)与这个问题有什么关系?评论应该是为了澄清一个问题,而不是宣传另一个问题。
标签: podio