GAE 用户身份验证不适用于 iPhone 上的channel_API
我有一个 GAE 应用程序,可以在浏览器中正常运行,但当我尝试在 iPhone 上运行同一网站时无法识别用户。 我正在使用当前的 user_id 通过通道 API 发送消息
这是我的 python GAE 应用程序中的代码 - 这里有两个定义 - send_update 和 send_update_iphone - 如您所见,它们完全相似!两者都在 Class 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。 这很有趣,但我仍然不知道如何解决......
I have a GAE app that works just fine from my browser, but can't figure out the user when I try to run the same website on the iphone.
I'm using the current user_id to send a message with the channel-API
This is the code in my python GAE app - here are two defs - send_update, and send_update_iphone - as you see they are totally similar! both are in the Class 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)
Now, I call them from different places, I call the first
Updater().send_update()
and the second
Updater().send_update_iphone()
When I use the application the first works beautifully - it opens the channel, and updates it on messages without a problem.
when I get to the app from the iphone (whilst logged-in to my gmail) I get:
'NoneType' object has no attribute 'user_id'
few details for the iPhone side:
- I get to the website from UIWebView
- I can see I'm logged-in to my google account
Can someone help? I tried anything I know >>> Thanks!
UPDATE: I checked the cookies (thanks Calvin) and saw that on the browser I get a cookie, but in the iphone I don't get a cookie (I use NSLog(@"Cookies: %@", [request1 responseCookies]);
)
I now know that in the browser it works because I get in the myapp.appspot.com page from my browser, so that's why it has the cookie, whilst from the iphone i POST to myapp.appspot.com, but I never get in the page itself, so the server never send me the cookie.
That's interesting, but I still don't know how to solve...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现问题是什么:iPhone 没有作为用户进行身份验证,因为我忘记将“
if not user:
”放在我请求 iphone 定向到的页面中(myapp.appspot因此,当然,当没有用户时, user.get_current_user() 会回复:
我现在要做的是首先加载 UIWebView 以转到 myapp.appspot.com/iphone - 以确保如果用户尚未登录,他会登录,然后重定向到我需要的任何地方。
I found what the problem was: the iphone didn't authenticate as a user, because I forgot to put the "
if not user:
in the page that I requested the iphone to direct to (myapp.appspot.com/iphone). So of course when there was no user the user.get_current_user() replied with:
What I do now is that I load the UIWebView first to go to myapp.appspot.com/iphone - to make sure that if the user haven't logged in, he will, and then redirect to wherever I need.