how to retrieve Facebook friend's group name? - ios

Facebook SDK 3.+ has requestForMyFriends, and return FBGraphUser but it doesn't have a group name property, is there a way to get all the groups belongs to the user?

You could easily grab all of a user's groups using the FB Open Graph and SLRequests. Ensure that you've already authenticated and then make the call like this:
NSURL *groups = [NSURL URLWithString:#"https://graph.facebook.com/me/groups"];
SLRequest *retrieveGroups = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:groups parameters:nil];
[retrieveGroups performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
//responseData contains your groups
}];

Related

Updating Twitter profile picture with iOS SLRequest results in error 215 bad authentication data

I am trying to post new profile picture according to Twitter's documentation at https://dev.twitter.com/rest/reference/post/account/update_profile_image and here is my code:
NSData *jpeg = UIImageJPEGRepresentation(img, 0.9);
NSString *base64 = [jpeg base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSURL *url = [NSURL URLWithString:#"https://api.twitter.com/1.1/account/update_profile_image.json"];
NSDictionary *params = #{#"image" : base64
};
SLRequest *request =
[SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:url
parameters:params];
[request setAccount:self.twitterAccount];
[request performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse,
NSError *error) {
...
}
But URL response is:
errors = (
{
code = 215;
message = "Bad Authentication data.";
}
);
What am I doing wrong? My ACAccount is valid (I've just tried signing out from and into Twitter in Settings.app).
You code seems fine, but you must be missing something.
Make sure that:
That your Twitter account is connected and is listed in the Settings app Twitter settings. I know you already checked, but it is essential that you verify it. Maybe even restart your phone and make sure your Twitter handle is there afterwards.
That your app has requested and granted permission to
access the account (using the requestAccessToAccountsWithType method). Once permission is granted, you should see your app listed in the Twitter settings (in the Settings app) under "ALLOW THESE APPS TO USE YOUR ACCOUNT".
The Twitter account that you're setting to the SLRequest is valid and is not nil.
Given the conditions above I was abled to modify my profile image successfully just now. Here's a sample code based on the code you've provided:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
{
if (granted)
{
NSArray *accounts = [accountStore accountsWithAccountType:accountType];
ACAccount *twitterAccount = [accounts lastObject];
NSData *jpeg = UIImageJPEGRepresentation([UIImage imageNamed:#"photo.jpg"], 0.9);
NSString *base64 = [jpeg base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:#"https://api.twitter.com/1.1/account/update_profile_image.json"]
parameters:#{#"image" : base64}];
[request setAccount:twitterAccount];
[request performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse,
NSError *error)
{
NSLog(#"%#", [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil]);
}];
}
}];

Facebook interests list not getting iOS

I am using SLRequest to get basic profile info. For getting interests i am using user_interests permission and the following code,
NSURL *meurl = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/me/interests"]];
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:meurl
parameters:nil];
merequest.account = _facebookAccount;
[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSError * error1=nil;
NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1];
}];
But the above code gives the empty response like as follows,
{
"data": [
]
}
Can anyone give the solution for this problem. Thanks.
There could be only 2 possible reasons for this-
There are no interests of the user queried (as #Tobi has mentioned), or
Your access token used by your api call do not have the permissions user_interests. This could be because you've added this permission later and since the session was active it didnt asked for the new permission.
You can check what permissions you've granted to the app from here
If this is the problem, you can either logout from the facebook in your app and login again or delete the app from here so that it will ask for the authorization again.
Hope that helps. Good luck

Custom iOS Tweet Sheet

I am looking to have a custom looking tweet sheet to use in my application.
Obviously I can build my own and use the twitter API for posting; however, this would SEEM (Maybe its not THAT MUCH work, I can't say) to take a lot of work to build, especially in features like autocomplete for user twitter followers etc.
Is there anyway to customize the tweet sheet used by Apple's frameworks? It just looks god awful, especially compared to the design of my app.
If not, where can I look to implement the displaying friend results while typing in #user?
Any thoughts, idea's, links, suggestions would be great. Thanks in advance!
You can use Social.framework for signing your requests with data from accounts, which is in system.
Second step - make your own view for tweeting.
Third - get ACAccount.
Like this:
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *accountTypeTwitter = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[store requestAccessToAccountsWithType:accountTypeTwitter options:nil completion:^(BOOL granted, NSError *error) {
if(granted) {
dispatch_sync(dispatch_get_main_queue(), ^{
NSArray *accounts = [store accountsWithAccountType:accountTypeTwitter];
//All twitter accounts are in array, show sheet to select one of them.
});
}
}];
Fourth - send SLRequest to twitter for post.
Example of SLRequest (to get information about user):
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"https://api.twitter.com/1.1/users/show.json?screen_name=%#",account.username]];
SLRequest *req = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:nil];
[req setAccount:account];
[req performRequestWithHandler:^(NSData *respData, NSHTTPURLResponse *resp, NSError *err){
//Req finished
}];
Here's a head start for your own custom tweet sheet:
https://github.com/doubleencore/DETweetComposeViewController

Like a facebook page using ios 6.0 social api

I want to implement like a page functionality using ios 6.0 social api. I think if I get exact Facebook Graph API link for like functionality then it possible. But I am not getting what's the exact url. Many are saying that it's not possible. I would like to know exact answer.
Please check and below code and response from Facebook.
{
"error": {
"message":"(#100) Like actions are not yet supported against objects of this type.",
"type":"OAuthException",
"code":100
}
}
Code :
NSURL *meurl = [NSURL URLWithString:#"https://graph.facebook.com/me/og.likes?"];
NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:account.credential.oauthToken,#"access_token",#"https://www.facebook.com/sample",#"object", nil];
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:meurl parameters:param];
merequest.account = account;
[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(#"%#",response);
}];

ios6 Tweet via SLRequest and edit the source field

I'm trying to edit the "source" field of a tweet that's documented: https://dev.twitter.com/docs/platform-objects/tweets
The below code successfully posts a tweet, however when I pull up that tweet on tweetdeck it still says it's being posted via ios. It feels like NSDictionary isn't the place to be editing this, however it doesn't seem like there's a better place in the flow and I can't find any examples/documentation to clear it up. Thanks for any help in advance.
NSDictionary *message = #{#"status": contents,
#"source": #"App Name"};
NSURL *requestURL = [NSURL
URLWithString:#"http://api.twitter.com/1/statuses/update.json"];
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:requestURL parameters:message];
postRequest.account = twitterAccount;
[postRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
NSLog(#"Twitter HTTP response: %i", [urlResponse
statusCode]);
}];
The documentation you're referring to explains the meaning of returned fields.
You cannot set the source by yourself, there's no API for that.
You can find the POST statuses/update API here.
Additionally, the code you posted uses API version 1 which was shut-down a while ago.
Now you have to use API version 1.1.

Resources