locked
FB login in Android (Bad Request 400) RRS feed

  • Question

  • User944339287 posted

    Hi guys.. my web application allowed visitor to login with fb a/c.

    it's working fine both in windows & ios's web browser except for ANDROID. Any idea?

    JSONtextForAccessToken:
    The remote server returned an error: (400) Bad Request.

                If String.IsNullOrEmpty(Request("code")) = False Then
    
                    Dim FACEBOOK_APP_ID As String = ConfigurationSettings.AppSettings("FACEBOOK_APP_ID").ToString
                    Dim FACEBOOK_APP_SECRET As String = ConfigurationSettings.AppSettings("FACEBOOK_APP_SECRET").ToString
                    Dim FACEBOOK_RETURN_URL As String = ConfigurationSettings.AppSettings("FACEBOOK_RETURN_URL").ToString + "/webpages/member_signin.aspx"
    
                    Dim GetAccessTokenUrl As String = "https://graph.facebook.com/oauth/access_token?client_id=" + FACEBOOK_APP_ID + "&redirect_uri=" + HttpUtility.HtmlEncode(FACEBOOK_RETURN_URL) + "&client_secret=" + FACEBOOK_APP_SECRET + "&code=" + Request("code")
                    Dim JSONtextForAccessToken As String = facebook.GetPageContent(GetAccessTokenUrl)
                    Dim jssForAccessToken = New JavaScriptSerializer()
                    Dim dictForAccessToken As Dictionary(Of String, Object)
    
                    Dim valid As Boolean = True
    
                    Try
                        dictForAccessToken = jssForAccessToken.Deserialize(Of Dictionary(Of String, Object))(JSONtextForAccessToken)
                    Catch ex As Exception
                        Response.Write(ex.Message & "<br>")
                        Response.Write(GetAccessTokenUrl & "<br>")
                        Response.Write(JSONtextForAccessToken & "<br>")
                        valid = False
                    End Try
    
    End If
        Protected Sub btn_FBlogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_FBlogin.Click
    
            Dim FACEBOOK_APP_ID As String = ConfigurationSettings.AppSettings("FACEBOOK_APP_ID").ToString
            Dim FACEBOOK_APP_SECRET As String = ConfigurationSettings.AppSettings("FACEBOOK_APP_SECRET").ToString
            Dim FACEBOOK_RETURN_URL As String = ConfigurationSettings.AppSettings("FACEBOOK_RETURN_URL").ToString + "/webpages/member_signin.aspx"
    
            Dim redirectUrl As String = "http://www.facebook.com/v2.5/dialog/oauth?client_id=" + FACEBOOK_APP_ID + "&redirect_uri=" + HttpUtility.HtmlEncode(FACEBOOK_RETURN_URL) + "&scope=email"
            Response.Redirect(redirectUrl, False)
    
        End Sub
    Wednesday, November 29, 2017 12:43 AM

All replies

  • User-1838255255 posted

    Hi kengkit,

    According to your description and error code, 400 error usually is related to the request. I suspect android browser add something to request header, so caused this issue.

    My suggestion is Capturing HTTP requests through tool, check the detailed request information in tool. Here is a tool of test this:

    Capturing HTTP requests:

    https://www.getpostman.com/docs/postman/sending_api_requests/capturing_http_requests 

    Also here is a tutorial about how to fix this type error, please check:

    400 Bad Request Error: What It Is and How to Fix It:

    https://airbrake.io/blog/http-errors/400-bad-request 

    Best Regards,

    Eric Du

    Wednesday, November 29, 2017 7:36 AM
  • User-655622114 posted

    The 400 Bad Request error is an HTTP status code indicates that the request you sent to the webserver was malformed , in other words, the data stream sent by the client to the server didn't follow the rules. It means that the request itself has somehow incorrect or corrupted and the server couldn't understand it. The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method . Therefore, it prevents the website from being properly displayed. There are a number of different causes for a 400 Bad Request Error . It might be a malformed request syntax, invalid request message framing, or deceptive request routing . In most cases, the problem is on the website itself, and there's not much you can do about that. To fix a 400 Bad Request error it is best to start diagnosing the issue from the client side itself. Complete the steps outlined in this section to help diagnose and correct the error.

    Check for errors in the URL.
    Clear Browser Cache and cookies.
    Clear DNS Cache.
    Check your File upload Size.
    Deactivate Browser Extensions.
    Contact the site owner to report the 404 error.

    Monday, January 27, 2020 6:06 AM