0

我想为 Android ebay 客户端写一点。

但我在第一个问题上苦苦挣扎。首先我用 IntelliJ 开始一个新的 Java Android 项目

我想使用这个库ebay-oauth-android-client

就像在 Git 上描述的那样:

获取库

该库通过 Maven 中央存储库分发。要使用此库,请将以下内容作为依赖项包含在您的项目中

 dependencies {
     compile 'com.ebay.auth:ebay-oauth-android-client:1.0.1'
 }

我把这个片段放在我的 Gradle.build 中,并用 implementation 替换 compile,因为 compile 被贬低了。

到目前为止,一切都很好。gradle 导入这个库。

但下一步对我不起作用:

应用程序设置 在执行 OAuth 之前,应该使用来自 eBay 开发人员门户的应用程序的详细信息初始化库。图书馆使用

客户 ID。有关详细信息,请参阅获取您的 OAuth 凭据重定向 Uri。有关详细信息,请参阅获取您的 Redirect_Uri Url 编码范围列表。有关详细信息,请参阅指定 OAuth 范围在 ApiSessionConfiguration.initialize() 中使用这些详细信息,如下所示:

 ApiSessionConfiguration.initialize(
                apiEnvironment = ApiEnvironment.PRODUCTION,
                apiConfiguration = ApiConfiguration(
                    <Client ID>,
                    <Redirect Uri>,
                    <space separated scopes>
                )
            )

所以我尝试调用initialze:

我的代码有错误

但是当我尝试编译器告诉我:

cannot find symbol method initialize(<null>)

当我跳转到 ApiSessionConfiguration 的类声明时,写的是:

// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available

package com.ebay.api.client.auth.oauth2.model

public final class ApiSessionConfiguration private constructor() {
    public companion object {
        private final val instance: com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration /* compiled code */

        public final fun getInstance(): com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration { /* compiled code */ }

        public final fun initialize(apiEnvironment: com.ebay.api.client.auth.oauth2.model.ApiEnvironment, apiConfiguration: com.ebay.api.client.auth.oauth2.model.ApiConfiguration): com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration { /* compiled code */ }
    }

    public final var apiConfiguration: com.ebay.api.client.auth.oauth2.model.ApiConfiguration? /* compiled code */

    public final var apiEnvironment: com.ebay.api.client.auth.oauth2.model.ApiEnvironment? /* compiled code */
}

我真的不明白我做错了什么。在 Git ApiSessionConfiguration.initialize() 的示例文件中调用没有任何错误。

我已经尝试过使缓存无效,清理构建,然后重新开始。当我尝试从 Maven 存储库中的新项目结构库导入库时,它说:没有下载文件...

4

1 回答 1

0

它不能initialize用单个参数解析方法吗?您是否尝试过initialize带有两个参数的方法?

他们的示例应用程序采用 2 个参数: https ://github.com/eBay/ebay-oauth-android-client/blob/master/sample/src/main/java/com/ebay/api/client/auth/MainActivity.kt #L37-L44

更新:但是要从 java 访问 Kotlin 伴随对象函数,您需要调用ApiSessionConfiguration.Companion.initialize方法

于 2020-05-05T07:19:26.077 回答