Guest User

Untitled

a guest
Aug 14th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. POST https://www.googleapis.com/blogger/v3/blogs/8070105920543249955/posts/
  2. Authorization: /* OAuth 2.0 token here */
  3. Content-Type: application/json
  4.  
  5. {
  6. "kind": "blogger#post",
  7. "blog": {
  8. "id": "8070105920543249955"
  9. },
  10. "title": "A new post",
  11. "content": "With <b>exciting</b> content..."
  12. }
  13.  
  14. //main.php
  15. $url = "https://accounts.google.com/o/oauth2/auth";
  16. $params = array(
  17. "response_type" => 'code',
  18. "client_id" => '<AUTH_ID>.apps.googleusercontent.com',
  19. "redirect_uri" => 'http://example.com/authCallback.php',
  20. "scope" => 'https://www.googleapis.com/auth/blogger');
  21.  
  22. $request_to = $url.'?'.http_build_query($params);
  23. header("Location: ".$request_to);
  24.  
  25. //authCallback.php
  26. if(isset($_GET['code'])) {
  27. // Get an access token
  28. $code = $_GET['code'];
  29. $url = 'https://accounts.google.com/o/oauth2/token';
  30. $apikey = '<API_KEY>';
  31. $blogId = '<BLOG_ID>';
  32. $params = array(
  33. "code" => $code,
  34. "client_id" => urlencode("<ID>.apps.googleusercontent.com"),
  35. "client_secret" => urlencode("<SECRET>"),
  36. "redirect_uri" => urlencode("http://example.com/authCallback.php"),
  37. "grant_type" => urlencode("authorization_code")
  38. );
  39.  
  40. // HTTP query builder
  41. foreach($params as $key=>$value) {
  42. $fields .= $key.'='.$value.'&';
  43. }
  44.  
  45. rtrim($fields, '&');
  46. $ch = curl_init();
  47. curl_setopt($ch, CURLOPT_URL, $url);
  48. curl_setopt($ch, CURLOPT_POST, TRUE);
  49. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  50. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  51. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  52. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  53. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  54. $data = curl_exec($ch);
  55. curl_close($ch);
  56. $response = json_decode($data);
  57. $accessToken = $response->access_token;
  58. }
Add Comment
Please, Sign In to add comment