首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iPhone Facebook app:“权限数组”代码在哪里?

iPhone Facebook app:“权限数组”代码在哪里?
EN

Stack Overflow用户
提问于 2011-07-03 00:46:35
回答 1查看 2.7K关注 0票数 2

我刚刚浏览了Facebook开发者的"Getting Started > Mobile Apps“文档。他们提供了代码来请求访问信息的许可,但他们没有指定代码应该放在哪里。

你能告诉我把代码放在哪里吗?因为我不想把它放错地方。

我想添加的代码如下:

代码语言:javascript
复制
NSArray* permissions =  [[NSArray arrayWithObjects:
     @"publish_stream", @"offline_access", nil] retain];

[facebook authorize:permissions delegate:self];

我的appDelegate代码:

代码语言:javascript
复制
#import "iOSTestAppDelegate.h"

@implementation iOSTestAppDelegate

@synthesize facebook;

@synthesize viewController=_ViewController;

@synthesize window=_window;

@synthesize managedObjectContext=__managedObjectContext;

@synthesize managedObjectModel=__managedObjectModel;

@synthesize persistentStoreCoordinator=__persistentStoreCoordinator;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];

    /* Step 2. Within the body of the application:didFinishLaunchingWithOptions: method create instance of the Facebook class using your app id */
    facebook = [[Facebook alloc] initWithAppId:@"********"];

    /* Step 3. Once the instance is created, check for previously saved access token information. */
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

    /* Step 4. Check for a valid session and if it is not valid call the authorize method which will both signin the user and prompt the user to authorize the app: */

    if (![facebook isSessionValid]) {
        [facebook authorize:nil delegate:self];
    }

    return YES;
}

/* Step 5. Add the application:handleOpenURL: method to the AppDelegate with a call to the facebook instance: */
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    return [facebook handleOpenURL:url]; 
}

/* Step 6. Implement the fbDidLogin method from the FBSessionDelegate implementation. In this method you will save the user's credentials specifically the access token and corresponding expiration date. */
- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];

}
...
@end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-03 01:13:32

分配facebook实例后,您必须提供这些权限,以便从user_credentials对facebook进行授权。这意味着我们从登录的用户那里获得了这些权限。

代码语言:javascript
复制
facebook=[[Facebook alloc]initWithAppId:kAppId];

_permissions =  [[NSArray arrayWithObjects:@"publish_stream",@"offline_access",nil]retain];

[facebook authorize:_permissions delegate:self];

发布流提供:使您的应用程序可以将内容、评论和点赞发布到用户的流和用户的朋友的流。使用此权限,您可以随时将内容发布到用户的提要,而不需要offline_access。但是,请注意,Facebook推荐用户发起的共享模式。

Offline Access:允许您的应用程序随时代表用户执行授权请求。默认情况下,大多数访问令牌在短时间后过期,以确保应用程序仅在活跃使用应用程序时才代表用户发出请求。此权限使我们的OAuth端点返回的访问令牌保持很长时间。

有关权限here的详细信息,请参阅

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6558308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档