开发者

GAE users authentication doesn't work from iphone for channel_API

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 th开发者_JS百科e 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...


I found what the problem was: the iphone didn't authenticate as a user, because I forgot to put the "if not user:

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

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:

'NoneType' object has no attribute 'user_id'

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜