gpt4 book ai didi

ios - Facebook SDK iOS 访问码问题

转载 作者:行者123 更新时间:2023-11-29 13:04:45 26 4
gpt4 key购买 nike

我的项目是在我的 iPhone 应用程序上获取我的粉丝专页的 Facebook Insights 数据。

我首先安装适用于 iOS 的 Facebook SDK 以获取访问代码,然后使用随 Facebook iOS SDK 提供的 SampleLoginSample 示例程序。

它的工作完美并给出与 Facebook API Explporer for Query 相同的响应

[self.textNoteOrLink setText:
[NSString stringWithFormat:@"https://graph.facebook.com/[PAGEID]?fields=likes&access_token=%@",appDelegate.session.accessTokenData.accessToken]];

但是如果我在下面写查询,它不会像在 Facebook Explorer API 中那样给我回复

查询:

[self.textNoteOrLink setText:
[NSString stringWithFormat:@"https://graph.facebook.com/PAGEID/insights/page_fans?access_token=%@",appDelegate.session.accessTokenData.accessToken]];

回复:

{"data":[

],"paging":{

"previous":"https:\/\/graph.facebook.com\/PAGEID\/insights\/page_fans?access_token=CAA...snip...h2l&since=1378984583&until=1379243783","next":"https:\/\/graph.facebook.com\/PAGEID\/insights\/page_fans?access_token=CAA...snip...h2l&since=1379502983&until=1379762183"}}

谁能帮我在 Facebook iOS SDK 中获取具有 get_insights 权限的访问代码?

最佳答案

SLAppDelegate.h

@property的列表下,添加:

-(BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI;

SLAppDelegate.m

applicationDidBecomeActive 下,添加:

/*
* Opens a Facebook session and optionally shows the login UX.
*/
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"read_insights",
nil];

return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}

和:

/*
* Callback for session changes.
*/
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
if (!error) {
// We have a valid session
NSLog(@"User session found");
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}

if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}

SLViewController.h

viewDidLoad的末尾,添加:

[appDelegate openSessionWithAllowLoginUI:NO];

关于ios - Facebook SDK iOS 访问码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18915539/

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