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);
}];
Related
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]);
}];
}
}];
I want my app to tag friend within a video-post.
(Posting a video without the tags is working fine)
The account I'm using, has been added to the list of testers for my app.
So I should be able to do this call without any permissions.
But the response is still:
"error: (#3) Application does not have the capability to make this API call."
To get the "Taggable Friends" permission, I need upload a build of my app to fb.
But I can't implement this feature without testing it by myself first.
How can I solve this chicken-and-egg problem?
My code looks like this (iOS - Objc):
NSDictionary *params = #{
#"title": #"some title",
#"description": #"some desctiption",
#"tags": _friendId
};
SLRequest *uploadRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:videourl
parameters:params];
I have found the solution.
You can't set the tag whithin the upload request (I still don't know why).
But you can tag a user in the video after you uploaded the video.
When the upload succeeded, you get a videoId:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingMutableContainers
error:&error];
_currentVideoId = json[#"id"];
With this id you can make a second request:
ACAccountCredential *fbCredential = [_facebookAccount credential];
NSString *accessToken = [fbCredential oauthToken];
NSString *urlStr = [NSString stringWithFormat: #"https://graph-video.facebook.com/%#/tags?access_token=%#&tag_uid=%#", _currentVideoId, accessToken, userId];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString: urlStr]
parameters: #{}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
//Do something
}];
});
To make the second request, you need the permission for #"user_videos".
If you want to tag more users, you need to make this request a few times. Maybe it's also possible with one request, but I didn't figuered out how to do it yet.
I have an app that uploaded photos on the fly and i'm trying to add the ability to upload to the users facebook fan page (that they administer).
The problem that i'm having is that i can sucessfully upload a photo to the fan page but it's not showing up on the fan page timeline, it's only showing up under the "Recent Posts by Others" section of the fan page.
I'm obviously not uploading these images properly. Here's my code:
ACAccountType * accountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[_accountStore requestAccessToAccountsWithType:accountType options:#{ACFacebookAppIdKey: #"XXXXXXXXXXXX", ACFacebookPermissionsKey : #[#"photo_upload",#"publish_stream", #"publish_actions", #"manage_pages"], ACFacebookAudienceKey : ACFacebookAudienceEveryone} completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray * accounts = [_accountStore accountsWithAccountType:accountType];
NSDictionary *fanPages = [[NSUserDefaults standardUserDefaults] objectForKey:FACEBOOK_PREF_FAN_PAGES_IDS];
//if using fan pages
if (fanPages.count)
{
for (id key in fanPages) {
//id is the key and the access token is the value
NSLog(#"access token:%#, fanpage id: %#", fanPages[key], key);
NSMutableString *requestURL = [NSMutableString stringWithFormat:#"https://graph.facebook.com/%#/photos/", key];
NSURL * url = [NSURL URLWithString:requestURL];
NSDictionary *parameters = #{#"access_token": [fanPages[key] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], #"no_story":#"0", #"message": hashtags};
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:url parameters:parameters];
[request addMultipartData:UIImageJPEGRepresentation(image, 0.9) withName:#"source" type:#"application/octet-stream" filename:#"media.png"];
//NSLog(#"%#",[accounts lastObject]);
[request setAccount:[accounts lastObject]];
//make request
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSLog(#"uploaded for %#",fanPages[key]);
NSString *respData = [[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding];
NSLog(#"responseData %#",respData);
NSLog(#"urlResponse for %#",urlResponse);
[self performSelectorOnMainThread:#selector(removeProgressView) withObject:nil waitUntilDone:NO];
}];
}
}
else
{
//upload to personal timeline
NSURL * url = [NSURL URLWithString:#"https://graph.facebook.com/me/photos"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:url parameters:nil];
[request addMultipartData:[hashtags dataUsingEncoding:NSUTF8StringEncoding] withName:#"message" type:#"multipart/form-data" filename:nil];
[request addMultipartData:UIImageJPEGRepresentation(image, 0.9) withName:#"source" type:#"application/octet-stream" filename:#"media.png"];
[request setAccount:[accounts lastObject]];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
[self performSelectorOnMainThread:#selector(removeProgressView) withObject:nil waitUntilDone:NO];
}];
}
} else {
//theres an error or they are not granted
}
Any Ideas on what i'm doing wrong? I've scoured the internet for days on this one and everything seems correct.
So it turns out that i was doing everything correctly, the problem was that if i left in:
[request setAccount:[accounts lastObject]];
This causes it to post on my behalf and wouldn't show up in the timeline. removing this code remedied the issue and all my posts are now showing up on the fan pages timeline from the fan page itself and not from my facebook user account.
Thanks Tobi, i kinda knew it was the access token and i thought i was passing it correctly, apparently i wasn't.
So just to re-iterate, don't use setAccount when posting to a fan page as it will overwrite the access_token with your user token and not the fan page token.
I'm looking to search for any of the following things, whichever seems to work the best:
Regular mentions of a topic ABC (ABC)
Hashtag mentions of a topic ABC (#ABC)
# mentions of a topic ABC (#ABC)
How do I use the API to search this? Is there a specific way to form the URL to search for any one of these? For example, I'm currently using https://api.twitter.com/1.1/statuses/user_timeline.json with a specified account.
EDIT: for example, I want to be able to get just the tweets that are shown on this page: https://twitter.com/search?q=%23FiveWordTechHorrors How do I do this from a developer point of view?
NSString *url = [NSString stringWithFormat:#"http://api.twitter.com/1.1/search/tweets.json?q=%#&result_type=recent&count=%i", toBeSearched, count];
url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:url] parameters:nil];
[twitterInfoRequest setAccount:twitterAccount];
[twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if ([urlResponse statusCode] == 429) {
//Rate Limit Reached
} else if (error) {
// Check if there was an error
}
// Check if there is some response data
if (responseData) {
NSError *error = nil;
NSArray *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
// Do Whatever you want to do, the result is an array of 'tweet objects'
}
}];
I want to make a post from my iOS app with a mention to some friends. I got his "id".
So i use the follow and isn't work:
NSString *textToShare = #"hello #[100003626828741]";
NSDictionary *parameters = #{
#"picture":picture,
#"name" : #"hello",
#"caption" : textToShare,
#"message" : textToShare,
};
NSURL *feedURL = [NSURL URLWithString:#"https://graph.facebook.com/me/feed"];
SLRequest *feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:feedURL
parameters:parameters];
feedRequest.account = [[ICollinaService instance] facebookAccount];
[feedRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
NSLog(#"Facebook HTTP response: %i", [urlResponse
statusCode]);
NSLog(#"Facebook HTTP response allHeaderFields: %#", [urlResponse
allHeaderFields]);
NSLog(#"Facebook HTTP error: %#", error);
}];
}
How can i mention a friend in my post?
Thanks
The result of the post is: hello #[100003626828741] as a caption and message, without changeing the id for the name with link/tag.
I don't think you can tag a friend in a post, but you can in an action.
I'm looking into the Facebook Open Graph API - https://developers.facebook.com/docs/opengraph/getting-started/
I dont know if this is the best way to go!?!
I find it disturbing that its easy to pick friends with friendPicker and post pictures is extremely easy with IOS 6.0 social framework but to post the two combined with open Graph seems very difficult in comparison. Its however the only solution I have found so far.