[英]How to get Email param of facebook using SLRequest in iOS Social Framework
[英]How to read any facebook user public timeline using iOS Social framework?
我真的花了幾個小時嘗試解決這個問題! 我只希望能夠從facebook讀取任何用戶的時間軸(公共消息)...從技術上講(為簡單起見),我寧願僅使用iOS sdk中的框架(即不必使用facebook)。 因此,我目前僅使用Social.framework和Accounts.framework
到目前為止,我成功完成的工作是,當我嘗試通過以下網址@“ https ”中的“ ANOTHER_USER_ID”支持“ me”時,請閱讀當前登錄用戶(在設備上標識的用戶)的Facebook時間軸: //graph.facebook.com/me/feed “,它僅返回一個空的數據字段(無“ message”節點)。
“奇怪”的事實是,我可以使用@“ https://graph.facebook.com/cocacola/feed ”成功訪問任何公司類型的提要(例如“可口可樂”)。
所以我的問題是如何達到“簡單”用戶的提要(例如“ shireesh.asthana”),以便我可以閱讀它的“消息”?
到目前為止,我的過程:
以下是我當前正在使用的代碼:
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// Specify App ID and permissions
NSDictionary *options = @{
ACFacebookAppIdKey: @"1111111111111", // My AppID here
//ACFacebookPermissionsKey: @[@"read_stream"],
ACFacebookPermissionsKey: @[@"email", @"read_stream"],
ACFacebookAudienceKey:ACFacebookAudienceFriends
};
[account requestAccessToAccountsWithType:accountType
options:options completion:^(BOOL granted, NSError *error)
{
if (granted == YES)
{
NSArray *arrayOfAccounts = [account
accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
ACAccount *facebookAccount = [arrayOfAccounts lastObject];
// I want the messages and the author
NSDictionary *parameters = @{@"fields": @"message,from"};
NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/HERE_THE_USER_ID/feed"]; // Work with "cocacola" but not with "shireesh.asthana"
SLRequest *getRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:feedURL
parameters:parameters];
getRequest.account = facebookAccount;
[getRequest performRequestWithHandler:
^(NSData *responseData, NSHTTPURLResponse
*urlResponse, NSError *error)
{
dataSource = [NSJSONSerialization
JSONObjectWithData:responseData
options:NSJSONReadingMutableLeaves
error:&error];
// Reach the main queue to process result
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Read %d messages", [dataSource[@"data"] count]);
if ([dataSource[@"data"] count] != 0) {
// Do stuff in case of success...
} else {
// Do stuff in case of ERROR...
}
});
}];
} else {
// Case of no facebook account on the device...
}
} else {
// User don't grant the app to access its facebook info...
}
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.