0

我有一个 GAE 应用程序可以在我的浏览器上正常运行,但是当我尝试在 iphone 上运行相同的网站时无法识别用户。我正在使用当前的 user_id 通过通道 API 发送消息

这是我的 Python GAE 应用程序中的代码——这里有两个定义——send_update 和 send_update_iphone——正如你所见,它们完全相似!两者都在类 Updater() 中:

Updater():
     def send_update(self):
        message = self.get_fetch_message()
        user = users.get_current_user()
        channel.send_message(user.user_id()+user.user_id(),message)



    #for iphone - no user yet...
    def send_update_iphone(self):
        message = self.get_fetch_message()
        user = users.get_current_user()
        channel.send_message(user.user_id()+user.user_id(),message)

现在,我从不同的地方给他们打电话,我打电话给第一个

Updater().send_update()

第二个

Updater().send_update_iphone()

当我使用该应用程序时,第一个效果很好 - 它打开了频道,并毫无问题地根据消息更新它。当我从 iphone 访问应用程序时(登录到我的 gmail 时),我得到:

“NoneType”对象没有属性“user_id”

iPhone 端的一些细节: - 我从 UIWebView 访问网站 - 我可以看到我已登录到我的谷歌帐户

有人可以帮忙吗?我试过任何我知道的东西>>>谢谢!

更新:我检查了 cookie(感谢 Calvin)并看到在浏览器上我得到了一个 cookie,但在 iphone 中我没有得到一个 cookie(我使用NSLog(@"Cookies: %@", [request1 responseCookies]);

我现在知道在浏览器中它可以工作,因为我从浏览器进入 myapp.appspot.com 页面,所以这就是它有 cookie 的原因,而从 iphone 我 POST 到 myapp.appspot.com,但我从来没有进入页面本身,所以服务器永远不会向我发送 cookie。这很有趣,但我仍然不知道如何解决......

4

1 回答 1

1

我发现问题出在哪里: iphone 没有以用户身份进行身份验证,因为我忘了把“if not user:

    self.redirect(users.create_login_url(self.request.uri))

在我请求 iphone 定向到的页面中 (myapp.appspot.com/iphone)。所以当然当没有用户时 user.get_current_user() 回复:

“NoneType”对象没有属性“user_id”

我现在要做的是首先加载 UIWebView 以访问 myapp.appspot.com/iphone - 以确保如果用户尚未登录,他会,然后重定向到我需要的任何地方。

于 2011-03-16T10:10:23.443 回答