如何使用GitLab Java API(gitlab4j)访问公共存储库?

huangapple go评论79阅读模式
英文:

How to access pubilc repository using GitLab java API, gitlab4j?

问题

我刚刚尝试使用gitlab4j API,以便访问一个公开的GitLab仓库,至少在第一步中,我真的不想通过添加身份验证详细信息来限制自己。

那么,有没有一种方式可以将此存储库作为公共资源进行访问?以及从API中登录和获益的最合适方式是什么?

请注意,我正在尝试访问的存储库和项目是具有公共访问权限的。

谢谢。


嗨@AlexRudenko,实际上我尝试了很多种方法,之后我发现“AccessToken”的方式是首选方式,我尝试了这样做:GitLabApi gitLabApi = new GitLabApi(“gitlab.com”,“MY_ACCESS_TOKEN”); List <Release> releases = gitLabApi.getReleasesApi()。getReleases(14100417); System.out.println(releases.get(0).getName()); 但是,不幸的是没有成功,发生了以下错误:

Exception in thread“main”java.lang.NoSuchMethodError:com.fasterxml.jackson.databind.JavaType.isReferenceType()Z at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:405)at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:349)at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:444)at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:182)at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:27)at com.fasterxml.jackson.databind.DeserializationContext.handleSecondaryContextualization(DeserializationContext.java:682)at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:482)at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:4178)at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3997)at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3072)at org.gitlab4j.api.Pager.<init>(Pager.java:95)at org.gitlab4j.api.ReleasesApi.getReleases(ReleasesApi.java:47)at org.gitlab4j.api.ReleasesApi.getReleases(ReleasesApi.java:33)at com.atypon.externaltaxonomies.GitLabTest.main(GitLabTest.java:31)

当尝试使用相同的ProjectId使用ReleaseApi时,出现了相同的错误。因此,我在想这里,我是否正确使用了Tags/ReleasesApi来确定项目?或者我在这里遗漏了什么?

英文:

I've just tried to use gitlab4j API, in order to access a public GitLab repository, and I really don't want to restrict myself by adding authentication details, at least in the first step.

So, is there a way to access this repository as a public thing? and what is the most appropriate way to login and benefit from this API?

Note that the repository and project that I'm trying to access into, is Public access one.

Thanks.


Hi @AlexRudenko, Actually I've tried many ways, and after I find that the "AccessToken" way is the preferable one, I tried this: GitLabApi gitLabApi = new GitLabApi(&quot;gitlab.com&quot;, &quot;MY_ACCESS_TOKEN&quot;); List&lt;Release&gt; releases = gitLabApi.getReleasesApi().getReleases(14100417); System.out.println(releases.get(0).getName()); But, with no luck unfortunately, this is the error was occurring:

Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.JavaType.isReferenceType()Z at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:405) at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:349) at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264) at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244) at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142) at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:444) at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:182) at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:27) at com.fasterxml.jackson.databind.DeserializationContext.handleSecondaryContextualization(DeserializationContext.java:682) at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:482) at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:4178) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3997) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3072) at org.gitlab4j.api.Pager.&lt;init&gt;(Pager.java:95) at org.gitlab4j.api.ReleasesApi.getReleases(ReleasesApi.java:47) at org.gitlab4j.api.ReleasesApi.getReleases(ReleasesApi.java:33) at com.atypon.externaltaxonomies.GitLabTest.main(GitLabTest.java:31)

And the same error appeared when tried to use the ReleaseApi with the same ProjectId.
So, I'm wondering here, am I using the Tags/RelasesApi in the correct way with regards to determining the project? or I missed something here?

答案1

得分: 1

最后提到的异常是因为缺少依赖项。

我刚刚添加了:

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.11.0</version>
        </dependency>

然后一切都按预期运行。
关闭中...

英文:

The last exception I mentioned, appeared bcz of dependencies-missed.

I've just added:

        &lt;dependency&gt;
            &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
            &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
            &lt;version&gt;2.11.0&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
            &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
            &lt;version&gt;2.11.0&lt;/version&gt;
        &lt;/dependency&gt;

and everything ran as expected.
closing...

huangapple
  • 本文由 发表于 2020年5月4日 04:13:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/61581005.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定