0
votes

I get code from this direct url with my client id and redirect uri; https://foursquare.com/oauth2/authenticateclient_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_REGISTERED_REDIRECT_URI

But I can't do it with the rest service. I have to embed this service in my java application and then get access token. I can use that different option,if there is another way you know to get access token.Can you help me?

2
You mean you have no substantive server code?Kosuke Ogawa
There should be oauth java libraries out there to help you with this. If you only need this token once, you could use a tool like Postmanenc_life
I need java source code to generate access token for social apis -- etc foursquareB.T

2 Answers

1
votes

The Foursquare docs walk through the process in great detail. There are 2 options:

  • Web Applications Code Flow
  • Web Applications Token Flow

Both these options will require you to setup an app through the Foursquare Developer site. You'll need to setup a redirect URL for Foursquare to redirect back to. This is usually a publically accessible URL, but a locahost URL also works for testing purposes.

The first, the Code Flow, follows a standard OAuth process:

  1. Direct users (generally done through a link or button) to

    https://foursquare.com/oauth2/authenticate?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_REGISTERED_REDIRECT_URI`
    
  2. If the user accepts, they will be redirected back to

    https://YOUR_REGISTERED_REDIRECT_URI/?code=CODE
    
  3. Your server should exchange the code it got in step 2 for an access token. Make a request for

    https://foursquare.com/oauth2/access_token?client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=authorization_code&redirect_uri=YOUR_REGISTERED_REDIRECT_URI&code=CODE
    
  4. The response will be JSON

    { access_token: ACCESS_TOKEN } 
    

This access token is what you're looking for.

The second method, the token flow is slightly easier:

  1. Redirect users who wish to authenticate to

    https://foursquare.com/oauth2/authenticate?client_id=CLIENT_ID&response_type=token&redirect_uri=YOUR_REGISTERED_REDIRECT_URI
    
  2. If a user accepts, they will be redirected back to

    https://YOUR_REGISTERED_REDIRECT_URI/#access_token=ACCESS_TOKEN
    

This access_token query param is what you're looking for.

0
votes
  1. Go to your "App Settings" page on the developer console of Foursquare.com

  2. Set the "Redirect URL" under "Web Addresses" to https://www.google.com

  3. Paste and enter the following url in your web browser (replace YOUR_CLIENT_ID with your actual client id):
    https://foursquare.com/oauth2/authenticate?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=https://www.google.com

    This should redirect you to a google page requesting permission to make the connection.

  4. Accept and then look at the url of your web browser (take note at the CODE part of the url to use in step 5)
    It should look like https://www.google.com/?code=CODE

  5. Copy the code value from the previous step.
    Paste and enter the following into your web browser (replace placeholders with actual values):
    https://foursquare.com/oauth2/access_token?client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=authorization_code&redirect_uri=https://www.google.com&code=CODE.

  6. When you paste the link , This should lead you to a page that gives you your access token.

Credit : IBM course intructor.