移动应用程序”文档。他们提供了请求访问信息权限的代码,但他们没有指定该代码应该去哪里。 你能告诉我把代码放在哪里吗?因为不想放错地方。 我要添-6ren">
gpt4 book ai didi

iPhone Facebook 应用 : Where does the "permissions array" code go?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:14 25 4
gpt4 key购买 nike

我刚刚浏览了有关 Facebook 开发人员的“入门 > 移动应用程序”文档。他们提供了请求访问信息权限的代码,但他们没有指定该代码应该去哪里。

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

我要添加的代码:

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

[facebook authorize:permissions delegate:self];

我的 appDelegate 代码:

#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

最佳答案

分配您的 facebook 实例后,您必须提供这些权限以从 user_credentials 授权 facebook。这意味着正在从登录用户那里获得这些许可。

facebook=[[Facebook alloc]initWithAppId:kAppId];

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

[facebook authorize:_permissions delegate:self];

发布流提供:使您的应用能够将内容、评论和点赞发布到用户的流和用户 friend 的流中。通过此权限,您可以随时将内容发布到用户的供稿中,而无需 offline_access。但是,请注意,Facebook 推荐用户发起的共享模式。

离线访问: 使您的应用程序能够随时代表用户执行授权请求。默认情况下,大多数访问 token 会在短时间后过期,以确保应用程序仅在用户主动使用应用程序时代表用户发出请求。此权限使我们的 OAuth 端点返回的访问 token 长期存在。

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

关于iPhone Facebook 应用 : Where does the "permissions array" code go?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6558308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com