Xero PHP API 错误:“您无权访问此资源”

我的 Xero API 设置和 OAuth 流程正在运行。我已将“英国演示公司”链接为租户(组织),并已向我的用户授予顾问 • 联系银行账户管理员、薪资管理员 • 费用(管理员)权限(似乎是最高级别),位于此处:https ://go.xero.com/Settings/Users但我仍然收到以下错误。“您无权访问此资源”我已经添加了应涵盖请求并具有有效访问令牌的所有范围,但仍然没有效果。


'client_id'     => env('XERO_CLIENT_ID'),

'client_secret' => env('XERO_CLIENT_SECRET'),

'redirect_uri'  => env('XERO_REDIRECT_URI'),

'scope'         => 'openid email profile offline_access accounting.transactions accounting.contacts accounting.contacts.read accounting.reports.read',

示例函数进行基本调用以获取帐户内的用户。与 Xero 的连接正常,但一旦我尝试请求任何数据,就会抛出相同的错误。


public function testXero() {

        $xeroAccessToken = GlobalSetting::where('name', '=', 'xero_access_token')->first();

        $xeroTenantOrganisation = GlobalSetting::where('name', '=', 'xero_tenant_organisation_id')->first();


        $xero = new XeroApp(

            new AccessToken(

                array(

                    'access_token' => json_decode($xeroAccessToken->value)->id_token

                )

            ), $xeroTenantOrganisation->value

        );

        //dd( $xero ); //we have a succesfull connection here...

        

        # Retrieve all contacts

        $contacts = $xero->contacts()->get();                               


        dd($contacts); //error "You are not permitted to access this resource".

 }

有人遇到过这个问题吗?


紫衣仙女
浏览 71回答 3
3回答

慕慕森

问题是我id_token在创建new XeroApp类实例时通过了。我无法看到存储在数据库中的 JSON 对象中的所有其他对象(非常大)。有一个实际access_token值与我在通话中创建的其他一些有用信息一起存储。$xero = new XeroApp(    new AccessToken(        array(            'access_token' => json_decode($xeroAccessToken->value)->access_token,            'refresh_token' => json_decode($xeroAccessToken->value)->refresh_token,            'expires' => json_decode($xeroAccessToken->value)->expires,        )    ), $xeroTenantOrganisation->value);$contacts = $xero->contacts;dd($contacts);//RESULTS!!! YES我会保持这个线程开放,以防万一它可以帮助任何人。

白衣非少年

很好,保存尼克 - 是的,它id_token可以用于诸如“使用 Xero 注册”之类的事情,如果您的业务运营是财务数据的核心,这可能是一个巨大的优势。https://developer.xero.com/documentation/oauth2/sign-up它本质上使您能够在系统中配置帐户(使用解码的 ID 令牌名称/电子邮件)并在单个流程中同步其 Xero 数据。我们发现合作伙伴因此而显着减少了新注册用户的流失。综上所述, validaccess_token和 thetenant_id是进行授权 API 调用所需的东西。

陪伴而非守候

我遇到了同样的问题,我意识到我的租户 ID 错误。您必须确定所有凭据。
打开App,查看更多内容
随时随地看视频慕课网APP