Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

APIs

Roberto Rivera
Roberto Rivera
11,361 Points

Using cURL API to set session user after login.

Hello everyone,

I'm having some slight confusion on the use of a wrapper for cURL. I'm trying to create my own web app after the tutorial and I'm having problems with user data. So I can pull my information when I ask for it directly. <?php require DIR . '\vendor\autoload.php'; $api = new Milo\Github\Api;

$url = 'https://api.github.com/users/digitalvillainy'; $response = $api->get($url); $user = $api->decode($response); $display = '<img class="profileIcon" src="' . $user->avatar_url . '" />';

However what I would like is that after the oAuth authentication the user name is stored and then I can pass it to another part of my code so I can then start pulling that info from GitHub. There's something that's just not clicking. Here is my Authenticate.php file as well, minus client id and client secret. Thanks for any help in advanced.

<?php require_once DIR . '/vendor/autoload.php'; session_start();

$appUrl = 'http://port-80-nknab9ej1d.treehouse-app.com';

$config = new Milo\Github\OAuth\Configuration($clientId, $clientSecret, ['user', 'repo', 'commit']); $storage = new Milo\Github\Storages\SessionStorage; $login = new Milo\Github\OAuth\Login($config, $storage); $api = new Milo\Github\Api;

if ($login->hasToken()){ $token = $login->getToken(); $api->setToken($token); } else { if (isset($_GET['redirect'])){ $login->obtainToken($_GET['code'], $_GET['state']); header("Location: " . filter_input(INPUT_GET, 'redirect')); exit(); } else { $login->askPermissions("$appUrl/inc/authenticate.php?redirect=" . $_SERVER['REQUEST_URI']); } }