0

I am trying to learn retrofit2 by showing my project's GitLab name into recyclerView . but I can not find what is exactly what to do!!! according gitlab wiki I found private-tokens and list of projrct.

this is my baseUrl and I create a builder:

Retrofit.Builder builder = new Retrofit.Builder()
            .baseUrl("https://gitlab.com/api/v4/projects?private_token=xxxxxx")
            .addConverterFactory(GsonConverterFactory.create());

and this is my endpoint:

@GET("/users/:{userid}/projects")
Call<List<GitLabRepo>> reposForUser(@Path("userid") int user);

my GitLabRepo pojo class:

class GitLabRepo {

private String name;

public String getName() {
    return name;
}
}

after running I got this error:

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)

I know my problem is related to baseUrl but what is correct gitLab BaseUrl? I want just show my project name into list at recycelerview list.

******************Edit****************** I use of poster :

https://gitlab.com/api/v4/projects?private_token=******/users/:******/projects

And I got :

{
"message": "401 Unauthorized"
}

I see into Status codes at gitlab wiki and wrote there:

401 Unauthorized    The user is not authenticated, a valid user token is necessary.

but I have added Private Tokens .

sayres
  • 361
  • 1
  • 4
  • 15

1 Answers1

0

remove the forward slash '/' from get i.e,change your code like this

@GET("users/:{userid}/projects/")
Call<List<GitLabRepo>> reposForUser(@Path("userid") int user);

and add '/' in your endpoint like this

Retrofit.Builder builder = new Retrofit.Builder()
        .baseUrl("https://gitlab.com/api/v4/projects?private_token=xxxxxx/")
        .addConverterFactory(GsonConverterFactory.create());
Navneet Krishna
  • 5,009
  • 5
  • 25
  • 44
  • I do your suggestion but I still got above error:`Caused by: java.lang.IllegalArgumentException: baseUrl must end in /: https://gitlab.com/api/v4/projects?private_token=xxxxxxxx/` – sayres Oct 06 '17 at 10:48
  • have you added / at the end of base url after token,then add add '/' it after projects also like this users/:{userid}/projects/ – Navneet Krishna Oct 06 '17 at 10:49
  • yes. `.baseUrl("https://gitlab.com/api/v4/projects?private_token=xxxx/")` – sayres Oct 06 '17 at 10:52
  • then add add '/' after projects also like this users/:{userid}/projects/ – Navneet Krishna Oct 06 '17 at 10:54
  • maybe because of an unauthorized token, are you sure the value of private_token that you are passing is correct,you will have to use a valid token obtained from gitlab api – Navneet Krishna Oct 06 '17 at 11:03
  • yes, I have copied this token from my account setting into my gitlab profile. – sayres Oct 06 '17 at 11:07
  • try removing the ':' from @GET("users/:{userid}/projects/") – Navneet Krishna Oct 06 '17 at 11:47
  • I removed and I tested in poster :`https://gitlab.com/api/v4/projects?private_token=xxxxxx` and I got json response. not mine json project. but when I run this link as a base url at android studio I got `Caused by: java.lang.IllegalArgumentException: baseUrl must end in /: https://gitlab.com/api/v4/projects?private_token=xxxxx` – sayres Oct 06 '17 at 13:18