Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
create a gist using PHP and streams
<?php
include "github-creds.php"; // sets $access_token
ini_set('user_agent', "PHP"); // github requires this
$api = 'https://api.github.com';
$url = $api . '/gists'; // no user info because we're sending auth
// prepare the body data
$data = json_encode(array(
'description' => 'Inspiring Poetry',
'public' => 'true',
'files' => array(
'poem.txt' => array(
'content' => 'If I had the time, I\'d make a rhyme'
)
)
));
// set up the request context
$options = ["http" => [
"method" => "POST",
"header" => ["Authorization: token " . $access_token,
"Content-Type: application/json"],
"content" => $data
]];
$context = stream_context_create($options);
// make the request
$response = file_get_contents($url, false, $context);
@vishal068

This comment has been minimized.

Copy link

@vishal068 vishal068 commented Apr 3, 2021

Screenshot from 2021-04-03 11-34-37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment