如何在Facebook的API API中显示访问令牌? [英] How do I get the access token explicitly in the Facebook API for iPhone?

查看:103
本文介绍了如何在Facebook的API API中显示访问令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近下载了Facebook iPhone演示应用程序。我已经做了几次尝试来掌握身份验证过程,我完全感到困惑。似乎有很多示例代码已经在此版本的API中被废弃了。



在我的主视图控制器的.m文件中,我在开始时有以下几点:

  #importFBConnect.h
/ pre>

需要Facebook信息的按钮使用此行,与演示应用不变:

  [_ facebook requestWithGraphPath:@meandDelegate:self]; 

这将调用以下方法:

   - (void)request:(FBRequest *)request didLoad:(id)result {

我已经把这个方法的功能插入了。我从Facebook中提取了一些我需要的东西,并在HTTP POST命令中将其发送到我的后端。例如,[result objectForKey:@id]返回id,[result objectForKey:@name]返回名称。但是,[result objectForKey:@access_token]什么都不返回。这是非常令人沮丧的,因为我需要将访问令牌传递到我的Google App Engine用户管理后端以创建一个新的用户。所以,希望我的代码包括使我的授权策略清楚(无论是什么)。有谁知道如何在这个上下文中获取访问令牌?如果您能帮我解决我需要包含的头文件等等,我会感激的。



谢谢,



John

解决方案

我正在做同样的确切事情。我正在制作我自己的HTTP请求,所以我需要accessToken,而且更重要的是,即使没有过期请求,iOS Facebook SDK也不记得accessToken过去的发布!



调用[_facebook authorize:permissions delegate:self];在fbDidLogin委托调用中,您可以轻松地拉(假设您的脸书对象保留在_facebook中):

   - (void) fbDidLogin {
NSString * accessToken = _facebook.accessToken;
NSDate * expirationDate = _facebook.expirationDate;
}

Voilà。



要通过应用启动处理持久性,您可以保存此数据,并在任何请求之前手动设置这些访问器。


I downloaded the Facebook iPhone demo app recently. I have made several attempts to grasp the authentication process and I'm totally confused. There seems to be a lot of sample code out there that has been rendered obsolete in this version of the API.

In the .m file for my primary view controller, I have the following at the start:

#import "FBConnect.h"

The button that requires information from Facebook uses this line, unchanged from the demo app:

[_facebook requestWithGraphPath:@"me" andDelegate:self]; 

This calls the following method:

- (void)request:(FBRequest *)request didLoad:(id)result {

I have hacked my functionality into this method. I pull a few things I need from Facebook and send them to my backend in a HTTP POST command. For example, [result objectForKey:@"id"] returns the id and [result objectForKey:@"name"] returns the name. However, [result objectForKey:@"access_token"] returns nothing. This is very frustrating because I need to pass the access token to my Google App Engine user management back end to create a new user. So, hopefully the code I have included makes my authetication strategy clear (whatever it is). Does anyone know how I can get the access token in this context? I would appreciate it if you could help me out with what header files I need to have included etc. ?

Thanks,

John

解决方案

I'm doing the same exact thing you are. I'm making my own HTTP requests, so I need the accessToken, and what's more, the iOS Facebook SDK doesn't remember the accessToken past launches, even with a no-expire request!

After calling [_facebook authorize:permissions delegate:self]; In the fbDidLogin delegate call, you can easily pull (assuming you have the facebook object retained in _facebook):

- (void)fbDidLogin {
NSString *accessToken = _facebook.accessToken;
NSDate *expirationDate = _facebook.expirationDate;
}

Voilà.

To handle persistence through app launches, you can save this data and manually set those accessors prior to any requests.

这篇关于如何在Facebook的API API中显示访问令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆