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:
- how list of questions stackoverflow api based on search query?
- getting null response stack overflow api php
- 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:
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
you (as user) approve request made application. redirected link in there access_token.
grab access token there , put in link :
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
Post a Comment