Created
September 6, 2016 02:27
-
-
Save mahya8585/580d44a73fb3449d1f91297d73761f51 to your computer and use it in GitHub Desktop.
facebookのJS SDKでログイン・写真アップロード・投稿を行う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="ja"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>test room</title> | |
| <script> | |
| window.fbAsyncInit = function() { | |
| FB.init({ | |
| appId : '【facebookのアプリID】', | |
| xfbml : true, | |
| version : 'v2.7' | |
| }); | |
| }; | |
| (function(d, s, id){ | |
| var js, fjs = d.getElementsByTagName(s)[0]; | |
| if (d.getElementById(id)) {return;} | |
| js = d.createElement(s); js.id = id; | |
| js.src = "//connect.facebook.net/ja_JP/sdk.js"; | |
| fjs.parentNode.insertBefore(js, fjs); | |
| }(document, 'script', 'facebook-jssdk')); | |
| function uploadFacebook(imgUrl, message) { | |
| FB.login(function(){ | |
| console.log(imgUrl); | |
| FB.api('/me/photos', | |
| 'POST', | |
| { | |
| 'url': imgUrl, | |
| 'no_story': true | |
| }, | |
| function (response) { | |
| if (!response.error && response.id) { | |
| console.log(message); | |
| FB.api('/me/feed', | |
| 'post', | |
| { | |
| message: message, | |
| object_attachment: response.id | |
| } | |
| ); | |
| } | |
| } | |
| ) | |
| }, {scope: 'publish_actions'}); | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <div id="content" align="center"> | |
| <button onclick="uploadFacebook('【画像のURL】', '【投稿メッセージ】')">Post Facebook</button> | |
| </div> | |
| <!-- 特に手を入れずにlikeボタンとシェアボタンを付ける場合はこちら--> | |
| <!-- | |
| <div | |
| class="fb-like" | |
| data-share="true" | |
| data-width="450" | |
| data-show-faces="true"> | |
| </div> | |
| --> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment