英文:
ebay OAuth 2.0 library Cannot Resolve method initialize()
问题
我想为Android eBay客户端编写一些代码。
但是我在第一个问题上遇到了困难。
首先,我在IntelliJ中启动一个新的Java Android项目。
我想使用这个库 ebay-oauth-android-client
如Git上所述:
获取库
这个库通过Maven中央仓库分发。要使用这个库,在您的项目中包含以下依赖关系
dependencies {
implementation 'com.ebay.auth:ebay-oauth-android-client:1.0.1'
}
我将这个片段放在我的 Gradle.build 中,并将 compile 替换为 implementation,因为 compile 已经被弃用。
到目前为止,gradle 导入了这个库。
但是下一步对我来说行不通:
应用设置
在执行OAuth之前,应该使用来自eBay开发者门户关于您的应用程序的详细信息来初始化库。
客户端ID。有关详细信息,请参阅获取OAuth凭据
重定向URI。有关详细信息,请参阅获取重定向URI
编码的范围列表。有关详细信息,请参阅指定OAuth范围
在 ApiSessionConfiguration.initialize() 中使用这些详细信息,如下所示:
ApiSessionConfiguration.initialize(
apiEnvironment = ApiEnvironment.PRODUCTION,
apiConfiguration = ApiConfiguration(
<Client ID>,
<Redirect Uri>,
<以空格分隔的范围>
)
)
所以我尝试调用初始化:
但是当我尝试这样做时,编译器告诉我:
找不到符号方法 initialize(<null>)
当我跳转到 ApiSessionConfiguration 的类声明时,写着:
// 来自类文件的IntelliJ API反编译存根源代码
// 方法的实现不可用
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 /* 编译代码 */
public final fun getInstance(): com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration { /* 编译代码 */ }
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 { /* 编译代码 */ }
}
public final var apiConfiguration: com.ebay.api.client.auth.oauth2.model.ApiConfiguration? /* 编译代码 */
public final var apiEnvironment: com.ebay.api.client.auth.oauth2.model.ApiEnvironment? /* 编译代码 */
}
我真的不明白我做错了什么。在Git上的示例文件中,ApiSessionConfiguration.initalize() 被调用而没有任何错误。
我已经尝试过使缓存失效,清除构建,并重新开始。
当我尝试从“项目结构”库中导入库时,从Maven存储库中新建,它说:
没有下载任何文件...
英文:
i wanted to write a bit for Android ebay client.
but im struggeling with the first probleme.
first i start a new Java Android Project with IntelliJ
I want to use this Library ebay-oauth-android-client
like described on Git:
> Obtaining Library
>
> This library is distributed via maven central repository. To use this
> library, include the below as dependency in your project
>
dependencies {
compile 'com.ebay.auth:ebay-oauth-android-client:1.0.1'
}
i put this snippet in my Gradle.build and replace compile with implementation since compile is depricated.
so far so good. gradle import this library.
but the next step not working for me:
> Application Setup
Before performing OAuth, the library should be initialized with details about your application from eBay developer portal. The library uses
> Client ID. For details see Getting your OAuth credentials
Redirect Uri. for details see Getting your Redirect_Uri
Url encoded list of scopes. for details see Specifying OAuth scopes
Use these details in ApiSessionConfiguration.initialize() as shown below:
ApiSessionConfiguration.initialize(
apiEnvironment = ApiEnvironment.PRODUCTION,
apiConfiguration = ApiConfiguration(
<Client ID>,
<Redirect Uri>,
<space separated scopes>
)
)
So i try to call initialze:
But when i try that the Compiler tells me that:
cannot find symbol method initialize(<null>)
When i Jump to the Class Declaration of ApiSessionConfiguration is written that:
// 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 */
}
i dont really understand what im doing wrong. in the sample file on Git ApiSessionConfiguration.initalize() is called without any errors.
i already tried to Invalidate Cache, Clean Build, and start over again.
when i try to import the library from Project Structure Librarys New from Maven repo it says:
no files were downloaded...
答案1
得分: 0
无法解析initialize
方法并使用单个参数吗?
您尝试过使用两个参数的initialize
方法吗?
他们的示例应用接受两个参数:
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
方法。
英文:
Doesn't it can resolve initialize
method with single argument?
Did you tried initialize
method with two arguments?
Their sample app takes 2 arguments:
https://github.com/eBay/ebay-oauth-android-client/blob/master/sample/src/main/java/com/ebay/api/client/auth/MainActivity.kt#L37-L44
Updated:
But to access to Kotlin companion object function from java you need to call ApiSessionConfiguration.Companion.initialize
method
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论