2

I am a real beginner, but want to know more about using the API.

I need to be able to get a post tagged with and the have it displayed to me. I then enter either 1 or 2, and it will remove that tag and add or respectively.

Python would be the easiest for me, but I'm using Ubuntu so Bash is also fine.

I don't need a complete solution, but I would like some basic guidelines.

For example, what is the registration expecting for the OAuth 2.0 site? Do I need to own a site?

What is the Enable Client Side OAuth Flow for?

1 Answer 1

2

OK... I've just meddled with the API and editing.

So, to do what you want, here's what I would do (in steps:)

  1. Get the questions via /questions with the tagged being installation. Use Python to loop through items (the results) and show them to you one-by-one. Make sure you make new variables saving the title, body and tags (so you can edit the question)
  2. Use Python to let you say 1 or 2, each calling a function addTag
  3. The if statement you use for checking whether 1 or 2 has been inputted will call addTag with a parameter newTag being either system-installation or software-installation.

To edit:

Use /questions/{id}/edit:

  • title: same title
  • body: same title
  • tags: same tags minus the installation and with the appropriate new tag (in the parameters)
  • summary: summary either pre-defined or input()ted on run.

Using requests:

def editQuestion(questionId, access_token, site_name, key, postText, postSummary, postTags, postTitle):
    results = requests.post("https://api.stackexchange.com/2.2/questions/[question_ID]/edit",
              data={'body': postText,
                    'comment': postSummary,
                    'tags': postTags,
                    'title': postTitle,
                    'access_token': '[access token]',
                    'site': '[site_name]',
                    'key': '[key]'
                    }
    )

    print(results.text)

You use Client Side OAuth Flow mainly when you do not have a website yourself to let someone get an access token. So use this. See here for more details on authentication. You would need to send a new user to:

https://stackexchange.com/oauth/dialog?client_id=[CLIENT_ID]&scope=write_access&redirect_uri=http://stackexchange.com

^^edit the parameters as required!

2
  • Can I get the body source (markdown), rather than html? Commented May 25, 2015 at 21:19
  • 1
    @Tim Use the 'filter' to get the body_markdown (under question). (ie. !9YdnSIoOi) -> this Commented May 25, 2015 at 21:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.