gpt4 book ai didi

android - 改造后发布

转载 作者:搜寻专家 更新时间:2023-11-01 07:49:39 24 4
gpt4 key购买 nike

<分区>

当我尝试通过 Retrofit 2 库使用 POST 方法时出现错误。我想加入 vid.me 服务。这是该服务的 API https://docs.vid.me/#api-Oauth-Authorize但是当我尝试这样做时出现错误:

FATAL EXCEPTION: main
java.lang.IllegalArgumentException: @Field parameters can only be used with form encoding. (parameter #1)
for method VideoApi.getUserLogin
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:695)
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:686)
at retrofit2.ServiceMethod$Builder.parameterError(ServiceMethod.java:704)
at retrofit2.ServiceMethod$Builder.parseParameterAnnotation(ServiceMethod.java:476)
at retrofit2.ServiceMethod$Builder.parseParameter(ServiceMethod.java:328)
at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:201)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)
at retrofit2.Retrofit$1.invoke(Retrofit.java:145)
at $Proxy1.getUserLogin(Native Method)
at com.example.vid_me_app.FeedFragment.Authorize(FeedFragment.java:48)
at com.example.vid_me_app.FeedFragment$1.onClick(FeedFragment.java:36)
at android.view.View.performClick(View.java:4231)
at android.view.View$PerformClick.run(View.java:17537)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at dalvik.system.NativeStart.main(Native Method)

我的 API 类:

public interface VideoApi {

@GET("/videos/featured")
Call<Videos>getFeaturedVideo();
@GET("/videos/new")
Call<Videos>getNewVideo();
@POST("oauth/authorize")
Call<SignInResult> getUserLogin(@Field("username")String username,@Field("password")String password,Callback<SignInResults> callback);
}

我的 fragment :

public class FeedFragment extends Fragment {
EditText username;
EditText password;
Button btnLogin;
public static final String ROOT_URL = "https://api.vid.me/";
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_feed, container, false);
username = (EditText) rootView.findViewById(R.id.user_name_field);
password = (EditText) rootView.findViewById(R.id.password_field);
btnLogin = (Button)rootView.findViewById(R.id.button_login);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Authorize();
}
});
return rootView;
}
public void Authorize(){
Retrofit retrofitAdapter = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(ROOT_URL)
.build();
final VideoApi videoApi = retrofitAdapter.create(VideoApi.class);
// Call<SignInResults> call = videoApi.getUserLogin(username.getText().toString(),password.getText().toString(), new Callback<SignInResults>());
videoApi.getUserLogin(username.getText().toString(),password.getText().toString(), new Callback<SignInResults>() {
@Override
public void onResponse(Call<SignInResults> call, Response<SignInResults> response) {
Toast.makeText(getActivity(), response.body().getSignInResults().get(0).getCode(), Toast.LENGTH_SHORT).show();
}

@Override
public void onFailure(Call<SignInResults> call, Throwable t) {

}
});

}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com