如何使用 Facebook iOS SDK 检索 Facebook 响应
我正在使用适用于 iPhone 的 Facebook iOS SDK。我初始化 Facebook 实例
facebook = [[Facebook alloc] initWithAppId:kAppId];
然后登录:
[facebook authorize:permissions delegate:self];
登录 Facebook 后,我正在执行以下操作来获取用户个人资料信息:
[facebook requestWithGraphPath:@"me" andDelegate:self];
NSMutableData *response = [fbRequest responseText];
unsigned char *firstBuffer = [response mutableBytes];
NSLog(@"Got Facebook Profile: : \"%s\"\n", (char *)firstBuffer);
但是我在控制台上看到以下内容:
Got Facebook Profile: "(null)"
我做错了什么,我也相信 Facebook 的响应是一个 json 字符串,我希望获取该 json 字符串。
I am using the Facebook iOS SDK for iPhone. I initialize the Facebook instance
facebook = [[Facebook alloc] initWithAppId:kAppId];
And then I do login:
[facebook authorize:permissions delegate:self];
After I logged in to Facebook I am doing the following to get the user profile information:
[facebook requestWithGraphPath:@"me" andDelegate:self];
NSMutableData *response = [fbRequest responseText];
unsigned char *firstBuffer = [response mutableBytes];
NSLog(@"Got Facebook Profile: : \"%s\"\n", (char *)firstBuffer);
But I get the following on my console:
Got Facebook Profile: "(null)"
What am I doing wrong, also I believe that Facebook response is a json string and I am looking to get a hold of that json string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想也许我应该把它做成一个维基并告诉人们我是如何做的。因为很多人都面临着类似的问题。
我做的第一件事是。
在 Facebook.m 类中,我在以下方法中添加了以下语句,
这可以防止打开 Safari 页面以进行 facebook 登录,但它会在应用程序本身中弹出一个屏幕。然后我为Facebook创建了一个辅助类,头文件代码在这里。
.m 文件。
I thought may be I should make it a wiki and tell the people how I am doing it. because lot of people are facing similar problem.
The first thing that I did was.
In Facebook.m class I added the following statement in the following method
This prevents a safari page to get open for the facebook login, but it pops up a screen in app itself. Then i created a helper class for Facebook, the header file code is here.
The .m file.
感谢 Yogesh 的提示!
在 facebook.m 中,您还可以在授权方法中设置 safariAuth 参数。
Thanks for this hint Yogesh!
In facebook.m you can also set the safariAuth param in the authorize method.