0

Im really struggling w/ the OAuth for Khan Academy. This is for my class website (Im a teacher) and I want to pull in user data on particular students. If I could do the OAUTH I would be fine. Im using PHP.
There seems to be many librarys out there, I have been playing w/ Google Oauth (located here http://code.google.com/p/oauth-php/source/browse/trunk/example/client/twolegged.php)

I can formulate the token request fine, although when I call it in the script, it seems like it tries to redirect to another page and gets blocked there.
http://myonlinegrades.com/prealg/khan/oauth-php/example/client/twoleggedtest.php

Im really struggling - Id love any help you might offer.

Code below:

<?php

include_once "../../library/OAuthStore.php";
include_once "../../library/OAuthRequester.php";

// Test of the OAuthStore2Leg 
// uses http://term.ie/oauth/example/

$key = '*********';//'<your app's API key>';
$secret = '***********';//'<your app's secret>';
$callBack = "http://myonlinegrades.com/prealg/test2.php5";
$url = 'http://www.khanacademy.org/api/auth/request_token';

$options = array('consumer_key' => $key, 'consumer_secret' => $secret);
OAuthStore::instance("2Leg", $options);

$method = "GET";
//$params = null;
$params = array(oauth_consumer_key => $key,oauth_callback=>$callBack);
try
{
    // Obtain a request object for the request we want to make
    $request = new OAuthRequester($url, $method, $params);

    // Sign the request, perform a curl request and return the results, 
    // throws OAuthException2 exception on an error
    // $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string)
    $result = $request->doRequest();

    $response = $result['body'];

    if ($response != 'oauth_token=requestkey&oauth_token_secret=requestsecret') 
    {
        echo 'Error! $response ' . $response;
    }
    else 
    {
    }


    var_dump($response);
}
catch(OAuthException2 $e)
{
    echo "Exception" . $e->getMessage();
}

?>
Jeff
  • 12,147
  • 10
  • 51
  • 87
user2260700
  • 103
  • 8

1 Answers1

2

Not sure this is what you're looking for, but I put together a simple example of doing oAuth with Khan Academy using the Temboo SDK: take a look at https://github.com/matthewflaming/temboo-experiments/tree/master/KhanAcademyOauth

(Full disclosure: I work at Temboo)

mflaming
  • 1,167
  • 7
  • 8