General developer forum

stream_context_create & session_satrt()

 
Picture of A. Obeid
stream_context_create & session_satrt()
Particularly helpful Moodlers

Hi

$url = 'https://path/to/oauth/';
    $data = array('client_id' => CLIENT_ID,
        'scope' => 'scope_name',
        'redirect_url' => '../local/import_data/test_import.php',
        );

    $options = array(
        'http' => array(
            'header' => "Content-type: application/x-www-form-urlencoded",
            'method' => 'POST',
            'content' => http_build_query($data),
            'ignore_errors' => true
        )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context); 

i get ""status":"error: parameter missing"

in separate page on the Server with

session_start();
before :"status":"ok""

I also tried
$options = array(
        'http' => array(
            'header' => "Content-type: application/x-www-form-urlencoded",
            'Cookie'=>http_build_query(array(
                'sesskey'=>$USER->sesskey,                 
                 ))."\r\n",
            'method' => 'POST',
            'content' => http_build_query($data),
            'ignore_errors' => true
        )
    );

does anyone solve something like this?
Thx

 
Average of ratings: -
Picture of A. Obeid
Re: stream_context_create & session_satrt()
Particularly helpful Moodlers

Solved with "curl"

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, "client_id=" . CLIENT_ID . "&scope=scope_name&return_url=".$return_url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 $result = curl_exec($ch);

 
Average of ratings: -