0

我有一个脚本,基本上让用户能够在单击它时签入到特定位置。单击它后,它每次都会将它们检查到相同的位置。

在桌面上这工作正常,我怀疑它也适用于 Android。我有一个 WP,因此显然我想让它在那里工作。此功能几乎将专门用于移动设备,因此使其跨设备工作很重要。

现在,到实际问题。单击 WP 上的签入按钮后,它会加载一个空白页面并挂在那里。虽然这可能是它可能已经签入的信号,但当我看起来它没有。所以它挂在那里,什么也不做。

这是它所挂的 URL:https ://m.facebook.com/dialog/oauth?display=touch&domain=www.staffscuesociety.com&scope=publish_stream&api_key=API_KEY&app_id=APP_ID&locale=en_US&sdk=joey&access_token=ACCESS_TOKEN&client_id=CLIENT_ID&redirect_uri=http%3A% 2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D18%23cb%3Df35fef827217048%26origin%3Dhttp%253A%252F%252Fwww.staffscuesociety.com%252Ff166245837c3b6e%26ociedomain%3Dwww.stafflations%26domain%3Dwww.stafflations% 3Dopener%26frame%3Df398a7113310e64&origin=2&response_type=token%2Csigned_request

这是代码:

var button;

        (function(d){
          var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
          if (d.getElementById(id)) { return; }
          js = d.createElement('script'); js.id = id; js.async = true;
          js.src = "//connect.facebook.net/en_US/all.js";
          ref.parentNode.insertBefore(js, ref);
        }(document));

        window.fbAsyncInit = function() {
          FB.init({
            appId      : '260445377421174',
            channelUrl : '//www.staffscuesociety.com/checkin/channel.html'
          });

          button = document.getElementById('checkinWidget');
          if (!button) return;
          if (!getPost()) {
            allowCheckin();
          } else {
            allowUndo();
          }
        };

        function setPost(value) {
          var d = new Date();
          d.setDate(d.getTime() + (10 * 60 * 1000));
          document.cookie = 'post=' + escape(value) + ';expires=' + d.toUTCString();
        }

        function getPost() {
          return getCookie('post');
        }

        function getCookie(key) {
          currentcookie = document.cookie;
          if (currentcookie.length > 0) {
            firstidx = currentcookie.indexOf(key + '=');
            if (firstidx != -1) {
              firstidx = firstidx + key.length + 1;
              lastidx = currentcookie.indexOf(';', firstidx);
              if (lastidx == -1) {
                lastidx = currentcookie.length;
              }
              return unescape(currentcookie.substring(firstidx, lastidx));
            }
          }
          return '';
        }

        function checkin() {
          allowNothing();
          FB.login(function(response) {
            if (response.authResponse) {
              FB.api('/me/permissions', function (permissions) {
                if (permissions.data.length > 0 && permissions.data[0].publish_stream) {
                  FB.api('/me/feed', 'post', { message: null, place: '117072761683514' }, function(post) {
                    if (!post || post.error) {
                      showError();
                    } else {
                      setPost(post.id);
                      allowUndo();
                    }
                  });
                } else {
                  allowCheckin();
                }
              });
            } else {
              allowCheckin();
            }
          }, {scope : 'publish_stream'});
        }

        function undo() {
          allowNothing();
          FB.api('/' + getPost(), 'delete', function(response) {
            setPost('');
            allowCheckin();
          });
        }

        function allowNothing() {
          button.onclick = function() { };
          button.className = 'pressed';
        }

        function allowCheckin() {
          button.onclick = checkin;
          button.className = '';
        }

        function allowUndo() {
          button.onclick = undo;
          button.className = 'pressed tick';
        }

        function showError() {
          button.className = 'pressed error';
        }

    }
4

0 回答 0