oauth - How to get questions using StackOverflow API V 2.2 in PHP -


i working on project , want questions stack overflow using stack overflow api. searched way how achieve same here:

  1. how list of questions stackoverflow api based on search query?
  2. getting null response stack overflow api php
  3. how use stack overflow api in php

but found nothing useful old techniques. using old stack overflow api versions.

while going through stackapps read achieve task have register app. have registered app on www.stackapps.com. , got app id , secret key.

i visited here https://api.stackexchange.com/docs/authentication know how data stack api v 2.2. have given useful links data using stack overflow api v 2.0 using authentication via oauth 2.0

it says ask request user , "code" etc. got stuck here. should process in order move forward using php.

my app should this:

let input link : https://api.stackexchange.com/2.2/questions?order=desc&sort=activity&site=stackoverflow

i data of page in of 2 form either html or json.

can done without oauth. if not, please guide.

assuming have registered application.

go manage applications here https://stackapps.com/apps/oauth

enable client side flow within app settings.

now want create desktop application, following steps:

  1. first need access token redirecting user link: https://stackexchange.com/oauth/dialog?client_id=[your_app_id]&scope=private_info&redirect_uri=https://stackexchange.com/oauth/login_success

  2. you (as user) approve request made application. redirected link in there access_token.

  3. grab access token there , put in link :

https://api.stackexchange.com/2.2/questions?order=descsort=activity&site=stackoverflow&key=[your_app_key]&access_token=[your_access_token]&filter=withbody

this ready api.

get content using:

$context = stream_context_create(array('https' => array('header'=>'connection: close\r\n'))); $json_array = file_get_contents("your_api_url", false, $context); $data = json_decode(gzdecode($json_array),true); print_r($data); // show file data 

the data in json , compressed (in gzip from). decompressed , decoded json.

this should work. worked me. :)


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -