Quering Facebook notifications using Social framework in iOS 6 - iphone

I've looked around the Social Framework, but it's difficult to navigate. I figured out how to get the latest #mentions on twitter, which I do like so:
NSURL *mentionsURL = [NSURL URLWithString:#"http://api.twitter.com/1.1/statuses/mentions_timeline.json"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:#"3" forKey:#"count"];
[parameters setObject:#"0" forKey:#"include_entities"];
SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodGET
URL:mentionsURL
parameters:parameters];
[twitterInfoRequest setAccount:twitterAccount];
[twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
}];
I was wanting to adapt this to get the latest notifications from Facebook, but I'm unsure what to put in the URL and parameters to make this work.

Related

how to invite facebook friend in ios7?

am new in ios development
when i click "find your facebook friend" button then invitaion goes to this my salected friend
how can i code for this.am using facebook sdk framework.
NSLog(#"ID=%#",[_IDArray lastObject]);
NSLog(#"Event ID:%#",_eventID);
NSData *data = [_eventID dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(#"Event ID:%#",[json objectForKey:#"id"]);
NSURL *meurl = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/invited/%#",[json objectForKey:#"id"],[_IDArray lastObject]]];
//#"https://graph.facebook.com/EVENT_ID/invited?users=USER_ID1,USER_ID2,USER_ID3"
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:meurl
parameters:nil];
merequest.account = _facebookAccount;
[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(#"Data=%#",meDataString);
}];
}
}
but i want to use facebook sdk
please help out
Facebook have shared the way to send request and invitation as:Facebook tutorial friend requests

is it possible to tag a post/photo using ios social framework?

In my app I need to tag my photo/posts. Is this possible using social framework or Should I use Facebook-sdk for this?. Also can I get friends list from social framework? any help to achieve this?
Tagging a photo or post can only be done using the FacebookSDK for iOS while getting your friends list is possible using both the SocialFramework and the FacebookSDK for iOS.
You can use this code to get your friends list using the SocialFramework.
- (void)getFbFriends
{
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *facebookTypeAccount = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = #{
ACFacebookAppIdKey: facebookAppId,
ACFacebookPermissionsKey: #[#"email"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
};
[store requestAccessToAccountsWithType:facebookTypeAccount
options:options
completion:^(BOOL granted, NSError *error){
if(granted)
{
NSArray *accounts = [store accountsWithAccountType:facebookTypeAccount];
ACAccount *facebookAccount = [accounts lastObject];
NSURL *meurl = [NSURL URLWithString:#"https://graph.facebook.com/me"];
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:meurl
parameters:nil];
merequest.account = facebookAccount;
NSURL *requestURL = [NSURL URLWithString:#"https://graph.facebook.com/me/friends"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:requestURL parameters:#{#"fields":#"id,name,picture,first_name,last_name,gender"}];
request.account = facebookAccount;
[request performRequestWithHandler:^(NSData *data,
NSHTTPURLResponse *response,
NSError *error) {
if(!error)
{
NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if([list objectForKey:#"error"]!=nil)
{
// if error occured e.g. Invalid Auth etc.
}
else
{
NSMutableArray *FBFriends = [[NSMutableArray alloc] init];
[FBFriends addObject:[userInfo objectForKey:#"id"]];
NSLog(#"friends %#", list);
}
}
else
{
NSLog(#"Error");
}
}];
}
else
{
NSLog(#"Error grant access");
}
}];
}

Invite Facebook Friends in IOS6

I want to fetch the facebook friend list & send invitation for my app.
i tried following code:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];
NSLog(#"%#",accounts); `******//I got the null array ***********`
ACAccount *facebookAccount = [accounts lastObject];
NSString *acessToken = [NSString stringWithFormat:#"%#",facebookAccount.credential.oauthToken];
NSDictionary *parameters = #{#"access_token": acessToken};
NSURL *feedURL = [NSURL URLWithString:#"https://graph.facebook.com/me/friends"];
SLRequest *feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:feedURL
parameters:parameters];
feedRequest.account = facebookAccount;
[feedRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
NSLog(#"%#",[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}];
In iOS 6 use the facebook SDK:
#import <FacebookSDK/FacebookSDK.h>
and call:
[FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}];
result should be the data you're looking for.

How to like a facebook page/follow a twitter user using social framework in iOS 6?

Is there an easy way to like a facebook page/follow a twitter user using social framework in iOS 6?
I can post messages to the user's facebook/twitter account fine using the framework.
This is a method for following a user on twitter
-(void)followTwitter{
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
NSLog(#"this is the request of account ");
if (granted==YES) {
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
// Keep it simple, use the first account available
ACAccount *acct = [arrayOfAccounts objectAtIndex:0];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:#"FollowedUserNameHere",#"screen_name",#"TRUE",#"follow", nil];
TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:#"https://api.twitter.com/1.1/friendships/create.json"] parameters:dictionary requestMethod:TWRequestMethodPOST];
[request setAccount:acct];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if ([urlResponse statusCode] == 200)
{
// The response from Twitter is in JSON format
// Move the response into a dictionary and print
NSError *error;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
NSLog(#"Twitter response: %#", dict);
}
else
NSLog(#"Twitter error, HTTP response: %i", [urlResponse statusCode]);
}];
}
}
}];
}
and follow this link for liking facebook page
http://angelolloqui.blogspot.jp/2010/11/facebook-like-button-on-ios.html
It should be noted that as of iOS 6.0 TWRequest was deprecated in favor of SLRequest from the Social framework, eg the accepted answer at: Twitter SLRequest performRequestWithHandler - Could not prepare the URL request

Using Twitter API's upload_with_media with iOS SDK?

I've been looking for a Objective-C version of this PHP code sample on how to use Twitter's upload_with_media for an iPhone application.
I have been able to find one. Could you point me to ane example or explain how I could translate this code to Objective-C?
Thanks
You can Do like this for upload_with_media,
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:#"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:nil requestMethod:TWRequestMethodPOST];
UIImage * image = [UIImage imageNamed:#"myImage.png"];
//add text
[postRequest addMultiPartData:[#"I just found the secret level!" dataUsingEncoding:NSUTF8StringEncoding] withName:#"status" type:#"multipart/form-data"];
//add image
[postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:#"media" type:#"multipart/form-data"];
// Set the account used to post the tweet.
[postRequest setAccount:twitterAccount];
// Perform the request created above and create a handler block to handle the response.
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:#"HTTP response status: %i", [urlResponse statusCode]];
[self performSelectorOnMainThread:#selector(displayText:) withObject:output waitUntilDone:NO];
}];