0
我試圖通過將項目的GitLab名稱顯示到recyclerView中來學習retrofit2。但我無法找到究竟該做什麼! 根據gitlab wiki我發現projrct的私人標記和list。GitLap中的Retrofit2和baseurl
這是我的baseUrl和我創建了一個建設者:
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("https://gitlab.com/api/v4/projects?private_token=xxxxxx")
.addConverterFactory(GsonConverterFactory.create());
,這是我的終點:
@GET("https://stackoverflow.com/users/:{userid}/projects")
Call<List<GitLabRepo>> reposForUser(@Path("userid") int user);
我GitLabRepo POJO類:
class GitLabRepo {
private String name;
public String getName() {
return name;
}
}
運行我得到了後此錯誤:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sayres.createandroidclient/com.example.sayres.createandroidclient.MainActivity}: java.lang.IllegalArgumentException: baseUrl must end in /: https://gitlab.com/api/v4/projects?private_token=rjezfrSUTn3fcugxLujm/
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IllegalArgumentException: baseUrl must end in /: https://gitlab.com/api/v4/projects?private_token=xxxxxx/
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:513)
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:456)
at com.example.sayres.createandroidclient.MainActivity.onCreate(MainActivity.java:34)
at android.app.Activity.performCreate(Activity.java:6679)
我知道我的問題與baseUrl有關,但是什麼是正確的gitLab BaseUrl
? 我想只顯示我的項目名稱列表在recycelerview列表中。
******************編輯****************** 我用的海報:
https://gitlab.com/api/v4/projects?private_token=******/users/:******/projects
而且我得到了:
{
"message": "401 Unauthorized"
}
我看到成Status codes
在gitlab wiki並寫有:
401 Unauthorized The user is not authenticated, a valid user token is necessary.
,但我已經加入私人令牌。
我做你的建議,但我仍然得到了上面的錯誤:'引起:java.lang.IllegalArgumentException:baseUrl必須以/:https://gitlab.com/api/v4/projects?private_token = xxxxxxxx /' – sayres
結尾/你在基址的末尾加了/在令牌之後,然後在項目之後添加'/'它也會像這個users /:{userid}/projects/ –
是的。 '.baseUrl(「https://gitlab.com/api/v4/projects?private_token=xxxx/」)' – sayres