2016-04-25 9 views
1

私は自分のアプリでログイン機能を作成しようとしています.vid.meサービスのためにログインしてください。ここではAPIを使用しています(使用する必要があるもののlonk)https://docs.vid.me/#api-Auth-Create しかし私がそれをしたとき、私は自分のアプリケーションにブレークポイントを作成し、badrequest、code == 400を持っています。 これを修正するために、私が間違って何をする必要があるのですか?デバッガ用 コード:リクエストコード== 400、webserviceにログインしようとしています

rawResponse = {[email protected]} "Response{protocol=http/1.1, code=400, message=Bad Request, url=https://api.vid.me/auth/create}" 
body = {[email protected]} 
cacheControl = null 
cacheResponse = null 
request = {[email protected]} "Request{method=POST, url=https://api.vid.me/auth/create, tag=Request{method=POST, url=https://api.vid.me/auth/create, tag=null}}" 
handshake = {[email protected]} 
headers = {[email protected]} "Content-Type: application/json\nDate: Mon, 25 Apr 2016 12:59:49 GMT\nServer: nginx\nSet-Cookie: rid=5b6d76d16a2e4b64b8e1389422b37319; expires=Sat, 17-May-2031 01:48:34 GMT; Max-Age=475159725; path=/; domain=vid.me\nSet-Cookie: srid=frACyTReTbefXzqSuGQKkg-IggcXQ-KPkrv6l5cHG2qVwYlXc1tmaDhOs; expires=Sat, 17-May-2031 01:48:34 GMT; Max-Age=475159725; path=/; domain=vid.me\nX-Request-Time: 21\nX-Vidme-Authorization-Okay: false\nX-Vidme-Server-Id: d547f3205895e99e1b50ac97a00e7a74\nContent-Length: 92\nConnection: keep-alive\nOkHttp-Sent-Millis: 1461571136194\nOkHttp-Received-Millis: 1461571136469\n" 
message = "Bad Request" 
networkResponse = {[email protected]} "Response{protocol=http/1.1, code=400, message=Bad Request, url=https://api.vid.me/auth/create}" 
priorResponse = null 
protocol = {[email protected]} "http/1.1" 
code = 400 

myFragment:フラグメントのための

public class FeedFragment extends Fragment { 
    EditText username; 
    EditText password; 
    Button btnLogin; 

    public List<SignInResult> signInResult; 
    String username_value,password_value; 
    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); 

     username_value = username.getText().toString(); 
     password_value = password.getText().toString(); 

     Call<SignInResults> call = videoApi.insertUser(username_value,password_value); 
     call.enqueue(new Callback<SignInResults>() { 


      @Override 
      public void onResponse(Call<SignInResults> call, Response<SignInResults> response) { 
       SignInResults results = response.body(); 
       String usermame_result = results.signInResult.getCode(); 
       Log.d("Feed",usermame_result); 
      } 

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

      } 
     }); 
} 
} 

APIインタフェース:

public interface VideoApi { 

    @GET("/videos/featured") 
    Call<Videos> getFeaturedVideo(); 

    @GET("/videos/new") 
    Call<Videos> getNewVideo(); 

    @FormUrlEncoded 
    @POST("/auth/create") 
    Call<SignInResults>insertUser(@Field("username") String username, 
          @Field("password") String password 
          ); 
} 

SignInResultクラス:

public class SignInResult { 
    public String getAuthorization() { 
     return authorization; 
    } 

    public void setAuthorization(String authorization) { 
     this.authorization = authorization; 
    } 

    public String getCode() { 
     return code; 
    } 

    public void setCode(String code) { 
     this.code = code; 
    } 

    @SerializedName("authorization") 
    @Expose 
    private String authorization; 
    @SerializedName("code") 
    @Expose 
    private String code; 

    public String getUsername() { 
     return username; 
    } 

    public void setUsername(String username) { 
     this.username = username; 
    } 

    @SerializedName("username") 
    @Expose 
    private String username; 

    public String getUser_id() { 
     return user_id; 
    } 

    public void setUser_id(String user_id) { 
     this.user_id = user_id; 
    } 

    @SerializedName("user_id") 
    @Expose 
    private String user_id; 
} 

SignInResultsクラス:

public class SignInResults { 
public SignInResult signInResult; 

    public List<SignInResult> getSignInResults() { 
     return signInResults; 
    } 

    List<SignInResult> signInResults; 
} 

答えて

1

あなたのキー+秘密に許可ヘッダーを設定していないように私には見えます。このためのインジケータは、このレスポンスヘッダでもあります:X-Vidme-Authorization-Okay: false

私はあなたに実際のコードを与えることはできませんが、HTTP要求ヘッダーAuthorizationを値basic XXXに設定する必要があります。ここで、XXXはキー+コロン+あなたの秘密は、base64でエンコードされています。

あなたの鍵/ IDがfooだったし、あなたの秘密は(foo:bar base64エンコードがZm9vOmJhcg==ある)barだったのであれば、あなたはAuthorization: basic Zm9vOmJhcg==を送信する必要があります。

関連する問題