· 8 years ago · Jan 01, 2018, 06:08 PM
1var UserId = 0;
2
3 function LoginFB() //When we are logged in this shows our name.
4 {
5
6 FB.api('/me?fields=name,email', function(meResponse) //Do a graph request to /me
7 {
8 UserId=meResponse.id;
9 var fbdata = meResponse.id + "," + meResponse.name + "," + meResponse.email; //As per our format, 'id,name;'
10
11 gameInstance.SendMessage("UserManager", //Game object name, make sure this exists!
12 "LoggedIn", //Method to call
13 fbdata); //Our serialized facebook data
14 });
15 }
16
17
18
19 function SendAGift() // offer a gift to other users
20 {
21 var nItem=1;
22
23 // create Post in DB
24 jQuery.ajax({
25 url: 'http://www.xxxxxx.de/Game/xxxxxxxx.php',
26 type: 'POST',
27 data: {uid: UserId, fit: nItem},
28 success: function(datainit){
29
30 if(datainit != 0)
31 {
32 //datainit contains the ID of the entry in table FB_userposts
33 u="http://www.xxxxxxxxxx.de/Game/xxxxxxx.php?id="+nItem+"&did="+datainit;
34
35 FB.ui({
36 method: 'share',
37 href: u,
38 display: 'popup'
39 }, function(response){
40
41 if(response == null)
42 {
43
44 jQuery.ajax({
45 url: 'http://www.xxxxxxx.de/Game/xxxxxxxx.php',
46 type: 'POST',
47 data: {did: datainit, uid: UserId, fit: nItem},
48 success: function(data){
49 console.log(data);
50 },
51 error: function() {
52 console.log('Ein Fehler ist aufgetreten');
53 }
54 });
55 }
56 else if (response.error_code != null)
57 {
58
59 jQuery.ajax({
60 url: 'http://www.xxxxxxxxxxxx.de/Game/xxxxxxxxxxxxx.php',
61 type: 'POST',
62 data: {did: datainit, uid: UserId, fit: nItem},
63 success: function(data){
64 console.log(data);
65 },
66 error: function() {
67 console.log('Ein Fehler ist aufgetreten');
68 }
69 });
70 }
71 else
72 {
73
74 // add missing Data to Post
75 jQuery.ajax({
76 url: 'http://www.xxxxxxxxxxxxxxxxxxxxxx.de/Game/Updatexxxxxxxxxxxxxx.php',
77 type: 'POST',
78 data: {did: datainit, pid: response.post_id, uid: UserId, fit: nItem},
79 success: function(data){
80 console.log(data);
81 },
82 error: function() {
83 console.log('Ein Fehler ist aufgetreten');
84 }
85 });
86
87 }
88
89 });
90 }//if(data != 0)
91 },
92 error: function() {
93 console.log('Ein Fehler ist aufgetreten');
94 }
95 });
96
97 }
98
99
100
101 // This is called with the results from from FB.getLoginStatus().
102 function statusChangeCallback(response) {
103 // The response object is returned with a status field that lets the
104 // app know the current login status of the person.
105 // Full docs on the response object can be found in the documentation
106 // for FB.getLoginStatus().
107 if (response.status === 'connected') {
108 // Logged into your app and Facebook.
109
110 } else {
111 FB.login(function(checkLoginState) {
112 // handle the response
113
114 }, {scope: 'public_profile,email'});
115 }
116 }
117
118
119 //-------------- how to change this part below? ------------------------------------------------
120
121 // This function is called when someone finishes with the Login
122 // Button. See the onlogin handler attached to it in the sample
123 // code below.
124 function checkLoginState() {
125 console.log("checkLoginState");
126 FB.getLoginStatus(function(response) {
127 statusChangeCallback(response);
128 });
129 }
130
131 window.fbAsyncInit = function() {
132 FB.init({
133 appId : 'xxxxx',
134 cookie : true, // enable cookies to allow the server to access
135 // the session
136 xfbml : true, // parse social plugins on this page
137 version : 'v2.10' // use version 2.1
138 });
139
140 // Now that we've initialized the JavaScript SDK, we call
141 // FB.getLoginStatus(). This function gets the state of the
142 // person visiting this page and can return one of three states to
143 // the callback you provide. They can be:
144 //
145 // 1. Logged into your app ('connected')
146 // 2. Logged into Facebook, but not your app ('not_authorized')
147 // 3. Not logged into Facebook and can't tell if they are logged into
148 // your app or not.
149 //
150 // These three cases are handled in the callback function.
151
152 FB.getLoginStatus(function(response) {
153 statusChangeCallback(response);
154 });
155
156 };
157
158 // Load the SDK asynchronously
159 (function(d, s, id) {
160 var js, fjs = d.getElementsByTagName(s)[0];
161 if (d.getElementById(id)) return;
162 js = d.createElement(s); js.id = id;
163 js.src = "//connect.facebook.net/en_US/sdk.js";
164 fjs.parentNode.insertBefore(js, fjs);
165 }(document, 'script', 'facebook-jssdk'));