Cara menggunakan if else redirect javascript

Whether someone is not logged into your app or not logged into Facebook, you can use to prompt them to do both. If they aren't logged into Facebook, they'll be prompted to login and then move onto logging into your app. This is automatically detected, so you don't need to do anything extra to enable this behavior.

Cara menggunakan if else redirect javascript
Cara menggunakan if else redirect javascript

Invoking the Login Dialog and Setting the Redirect URL

Your app must initiate a redirect to an endpoint which will display the login dialog:

https://www.facebook.com/v15.0/dialog/oauth?
  client_id={app-id}
  &redirect_uri={redirect-uri}
  &state={state-param}

This endpoint has the following required parameters:

  • client_id. The ID of your app, found in your app's dashboard.
  • redirect_uri. The URL that you want to redirect the person logging in back to. This URL will capture the response from the Login Dialog. If you are using this in a webview within a desktop app, this must be set to https://www.facebook.com/connect/login_success.html. You can confirm that this URL is set for your app in the App Dashboard. Under Products in the App Dashboard's left side navigation menu, click Facebook Login, then click Settings. Verify the Valid OAuth redirect URIs in the Client OAuth Settings section.
  • state. A string value created by your app to maintain state between the request and callback. This parameter should be used for preventing Cross-site Request Forgery and will be passed back to you, unchanged, in your redirect URI.

For example, if your login request looks like:

https://www.facebook.com/v15.0/dialog/oauth?
  client_id={app-id}
  &redirect_uri={"https://www.domain.com/login"}
  &state={"{st=state123abc,ds=123456789}"}

then your redirect URI would be called with this:

https://www.domain.com/login?state="{st=state123abc,ds=123456789}"
    

It also has the following optional parameters:

  • https://www.facebook.com/v15.0/dialog/oauth?
      client_id={app-id}
      &redirect_uri={"https://www.domain.com/login"}
      &state={"{st=state123abc,ds=123456789}"}
    
    0. Determines whether the response data included when the redirect back to the app occurs is in URL parameters or fragments. See the section to choose which type your app should use. This can be one of:
    • https://www.facebook.com/v15.0/dialog/oauth?
        client_id={app-id}
        &redirect_uri={"https://www.domain.com/login"}
        &state={"{st=state123abc,ds=123456789}"}
      
      1. Response data is included as URL parameters and contains
      https://www.facebook.com/v15.0/dialog/oauth?
        client_id={app-id}
        &redirect_uri={"https://www.domain.com/login"}
        &state={"{st=state123abc,ds=123456789}"}
      
      1 parameter (an encrypted string unique to each login request). This is the default behavior if this parameter is not specified. It's most useful when your server will be handling the token.
    • https://www.facebook.com/v15.0/dialog/oauth?
        client_id={app-id}
        &redirect_uri={"https://www.domain.com/login"}
        &state={"{st=state123abc,ds=123456789}"}
      
      3. Response data is included as a URL fragment and contains an access token. Desktop apps must use this setting for
      https://www.facebook.com/v15.0/dialog/oauth?
        client_id={app-id}
        &redirect_uri={"https://www.domain.com/login"}
        &state={"{st=state123abc,ds=123456789}"}
      
      0. This is most useful when the client will be handling the token.
    • https://www.facebook.com/v15.0/dialog/oauth?
        client_id={app-id}
        &redirect_uri={"https://www.domain.com/login"}
        &state={"{st=state123abc,ds=123456789}"}
      
      5. Response data is included as a URL fragment and contains both an access token and the
      https://www.facebook.com/v15.0/dialog/oauth?
        client_id={app-id}
        &redirect_uri={"https://www.domain.com/login"}
        &state={"{st=state123abc,ds=123456789}"}
      
      1 parameter.
    • https://www.facebook.com/v15.0/dialog/oauth?
        client_id={app-id}
        &redirect_uri={"https://www.domain.com/login"}
        &state={"{st=state123abc,ds=123456789}"}
      
      7. Returns a comma-separated list of all Permissions granted to the app by the user at the time of login. Can be combined with other
      https://www.facebook.com/v15.0/dialog/oauth?
        client_id={app-id}
        &redirect_uri={"https://www.domain.com/login"}
        &state={"{st=state123abc,ds=123456789}"}
      
      0 values. When combined with
      https://www.facebook.com/v15.0/dialog/oauth?
        client_id={app-id}
        &redirect_uri={"https://www.domain.com/login"}
        &state={"{st=state123abc,ds=123456789}"}
      
      3, response data is included as a URL fragment, otherwise included as a URL parameter.
  • https://www.domain.com/login?state="{st=state123abc,ds=123456789}"
        
    0. A comma or space separated list of Permissions to request from the person using your app.
For Windows 8 Apps

If you are building Login for a Windows app you can use the Package Security Identifier as your redirect_uri. Trigger the Login Dialog by calling

https://www.domain.com/login?state="{st=state123abc,ds=123456789}"
    
2 and use the Login Dialog endpoint as the requestUri. Here is an example in JavaScript:

var requestUri = new Windows.Foundation.Uri(
  "https://www.facebook.com/v15.0/dialog/oauth?
    client_id={app-id}
    &display=popup
    &response_type=token
    &redirect_uri=ms-app://{package-security-identifier}");

Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAsync(
  options,
  requestUri)
  .done(function (result) {
    // Handle the response from the Login Dialog
  }
);

This will return control flow back to your app with an access token on success, or error on failure.

Handling Login Dialog Response

At this point in the login flow, the person will see the Login dialog and will have a choice of whether to cancel or to let the app access their data.

If the person using the app chooses OK on the Login dialog, they grant access to their public profile, friend list and any additional Permissions your app requested.

In all cases, the browser returns to the app, and response data indicating whether someone connected or cancelled is included. When your app uses the redirect method as above, the redirect_uri your app returns to will be appended with URL parameters or fragments (as per the chosen

https://www.facebook.com/v15.0/dialog/oauth?
  client_id={app-id}
  &redirect_uri={"https://www.domain.com/login"}
  &state={"{st=state123abc,ds=123456789}"}
0), which must be captured.

Because of the various combinations of code languages that could be used in web apps, our guide doesn't show specific examples. However most modern languages will be capable of URL parsing, as follows:

Client-side JavaScript can capture URL fragments (for example jQuery BBQ), whereas URL parameters can be captured by both client-side and server-side code (for example

https://www.domain.com/login?state="{st=state123abc,ds=123456789}"
    
5 in PHP,
https://www.domain.com/login?state="{st=state123abc,ds=123456789}"
    
6 in jQuery BBQ,
https://www.domain.com/login?state="{st=state123abc,ds=123456789}"
    
7 in Node.js or
https://www.domain.com/login?state="{st=state123abc,ds=123456789}"
    
8 in Python). Microsoft provides a guide and sample code for Windows 8 apps connecting to an "online provider" - in this case, Facebook.

When using a desktop app and logging in, Facebook redirects people to the redirect_uri mentioned above and places an access token along with some other metadata (such as token expiry time) in the URI fragment:

https://www.facebook.com/connect/login_success.html#
    access_token=ACCESS_TOKEN...

Your app needs to detect this redirect and then read the access token out of the URI using the mechanisms provided by the OS and development framework you are using. You can then skip straight to the step.


Canceled Login

If people using your app don't accept the Login dialog and clicks Cancel, they'll be redirected to the following:

Apa itu if else Javascript?

Percabangan if/else merupakan percabangan yang memiliki dua blok pilihan. Pilihan pertama untuk kondisi benar, dan pilihan kedua untuk kondisi salah (else).

Bagaimana cara memanggil fungsi di javascript?

Cara Memanggil/Eksekusi Fungsi Kita bisa memanggil fungsi di dalam kode Javascript dengan menuliskan nama fungsinya seperti ini: namaFungsi(); Contoh: // membuat fungsi function sayHello(){ console.log("Hello World!"); } // memanggil fungsi sayHello() // maka akan menghasilkan -> Hello World!