4

I would like to be able to have my application make a request to the Stack Exchange API to favorite a question for the current user. The API specifies that this can be done via:

/2.2/questions/{id}/favorite

where id is the question ID.

However, I'm getting a 404 response whenever I call the following:

https://api.stackexchange.com/2.2/questions/11541695/favorite

The Documentation also mentions that I would have to use an access_token, but I'm not sure how to send it with it request.

1 Answer 1

3

You cannot use a standard GET request. You must obtain the access_token and then POST the necessary parameters.

The steps are currently:

Setup:

  1. Register your app.
  2. Link it with a post here on Stack Apps that has a legitimate [app] or [script] tag. In most cases you will also tag it with .

In your app:

  1. Have the user authorize your app and obtain an access_token by following the instructions in the Authentication doc page. Be sure to include write_access in the requested scope.

    Note that there are two different auth recipes: explicit and implicit.
    Which one you are allowed to use is controlled by the Client Side Flow setting on your app's registration page (visible only to you).

    If Client Side Flow is Enabled use the "implicit" recipe.
    Otherwise, use the "explicit" steps.

    For faster and easier code, use a library or use the JavaScript SDK to handle authentication.

  2. Send a POST to

    https://api.stackexchange.com/2.2/questions/{id}/favorite
    

    with the following parameters at a minimum:

    id = {The question id -- same as in the POST URL}
    key = {Your app's key}
    site = stackoverflow //-- Or whatever site you're operating on
    preview = false
    access_token = {The access token you obtained in step 1}

  3. On success, the API will return JSON with a question object. EG:

    {
      "items": [
      ... {question details} ...
      ],
      "has_more": false,
      "quota_max": 10000,
      "quota_remaining": 9996
    }
    
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .