Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- POST https://www.googleapis.com/blogger/v3/blogs/8070105920543249955/posts/
- Authorization: /* OAuth 2.0 token here */
- Content-Type: application/json
- {
- "kind": "blogger#post",
- "blog": {
- "id": "8070105920543249955"
- },
- "title": "A new post",
- "content": "With <b>exciting</b> content..."
- }
- //main.php
- $url = "https://accounts.google.com/o/oauth2/auth";
- $params = array(
- "response_type" => 'code',
- "client_id" => '<AUTH_ID>.apps.googleusercontent.com',
- "redirect_uri" => 'http://example.com/authCallback.php',
- "scope" => 'https://www.googleapis.com/auth/blogger');
- $request_to = $url.'?'.http_build_query($params);
- header("Location: ".$request_to);
- //authCallback.php
- if(isset($_GET['code'])) {
- // Get an access token
- $code = $_GET['code'];
- $url = 'https://accounts.google.com/o/oauth2/token';
- $apikey = '<API_KEY>';
- $blogId = '<BLOG_ID>';
- $params = array(
- "code" => $code,
- "client_id" => urlencode("<ID>.apps.googleusercontent.com"),
- "client_secret" => urlencode("<SECRET>"),
- "redirect_uri" => urlencode("http://example.com/authCallback.php"),
- "grant_type" => urlencode("authorization_code")
- );
- // HTTP query builder
- foreach($params as $key=>$value) {
- $fields .= $key.'='.$value.'&';
- }
- rtrim($fields, '&');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
- $data = curl_exec($ch);
- curl_close($ch);
- $response = json_decode($data);
- $accessToken = $response->access_token;
- }
Add Comment
Please, Sign In to add comment