Using STTwitter Library how can I attach an image - ios

I'm kind of new on objective c, and I'm trying to do a twitter client. I'm using the STTwitter API. I'm using the for tweeting the method :
[twitter postStatusUpdate:twitterPostTweetText
inReplyToStatusID:nil
mediaURL:_twitterPostMediaURL
placeID:nil
latitude:latitud
longitude:longitud
successBlock:^(NSDictionary *status) {
self->twitterPostTweetText = #"";
self->twitterPostTweetStatus = #"OK";
self->latitud = nil;
self->longitud = nil;
self.twitterPostMediaURL = nil;
} errorBlock:^(NSError *error) {
self->twitterPostTweetStatus = error ? [error localizedDescription] : #"Unknown error";
}];
but it says that for sending an image attached I have to use NSUrl but I can't figure out how does it work. I want to send an image that I take with the camera roll.
Please, any ideas?

Use an NSURL instance representing the file path.
See the example in STTwitter demo https://github.com/nst/STTwitter/blob/master/demo_osx/STTwitterDemoOSX/STClientVC.m#L33-L48

Related

iOS linkedin share not working

I could not make work the new linkedin sdk. It just open the login view. When i logged in then it go to linked in account/profile rather then showing the share prompt. Do anyone have any blog or example with latest sdk ?
It just wasted my 3 days. Please help.
NSArray *permissions = [NSArray arrayWithObjects:LISDK_W_SHARE_PERMISSION, nil];
[LISDKSessionManager createSessionWithAuth:permissions state:nil showGoToAppStoreDialog:YES successBlock:^(NSString *returnState)
{
NSLog(#"%s","success called!");
NSString *url = #"https://api.linkedin.com/v1/people/~/shares";
NSString *payload = #"{\"comment\":\"Check out developer.linkedin.com! http://linkd.in/1FC2PyG\",\"visibility\":{ \"code\":\"anyone\" }}";
if ([LISDKSessionManager hasValidSession])
{
[[LISDKAPIHelper sharedInstance] postRequest:url stringBody:payload
success:^(LISDKAPIResponse *response)
{
// do something with response
NSLog(#"response : %#",response.data);
}
error:^(LISDKAPIError *apiError) {
// do something with error
NSLog(#"error: %#",apiError);
}];
}
}
errorBlock:^(NSError *error){
NSLog(#"%s","error called!");
}];
//
I'm facing the same issue.This is an effective method but not a good idea: UIApplication.sharedApplication().openURL(NSURL(string: "https://www.linkedin.com/shareArticle?mini=true&url=http://developer.linkedin.com&title=LinkedIn%20Developer%20Network&summary=My%20favorite%20developer%20program&source=LinkedIn")!)
If you successfully share something via the SDK for iOS,please let me know.
Just use a URL like this and hyperlink your share button/icon/text...
https://www.linkedin.com/sharing/share-offsite/?url={url}
Source: Microsoft LinkedIn Share URL Documentation.
For example, this works for me:
https://www.linkedin.com/sharing/share-offsite/?url=http://www.wikipedia.org/
Works fine:

Posting a GIF to Tumblr from iOS?

There doesn't appear to be a straight forward way to post a GIF to Tumblr from an iPhone device?
I use the TMTumblrSDK for oauth authentication, but I haven't found a way to get a GIF posted to Tumblr after authenticating. Using the post: methods always give me an error.
Not only that, but it appears even the native client doesn't post GIFs correctly, so I'm wondering if GIFs can even be posted from mobile.
Here is the main chunk of code that matters:
[TMAPIClient sharedInstance].OAuthConsumerKey = #"consumerKeyHere";
[TMAPIClient sharedInstance].OAuthConsumerSecret = #"secretHere";
[TMAPIClient sharedInstance].OAuthToken = #"token";
[TMAPIClient sharedInstance].OAuthTokenSecret = #"tokenSecret";
[[TMAPIClient sharedInstance] authenticate:#"testApp" callback:^(NSError * error) {
//authenticating works
[[TMAPIClient sharedInstance] userInfo:^(id userInfo, NSError *error) {
//userInfo works
NSString * stringData = [gifData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
[[TMAPIClient sharedInstance] post:#"myTumblrDomain.tumblr.com" type:#"photo" parameters:#{#"data": stringData,
#"tags": #"test",
#"caption": #"Test caption"} callback:^(id moreInfo, NSError *error) {
//401 here. Works if I use a text post instead
NSLog(#"Post Info %# Error %#", moreInfo, error);
}];
}];
}];

get share link (file link) for BOX in iOS

I am using box SDK V2 and the folder picker present in the sample app. I do not need any upload or download facility. I just need to get the file's ShareLink.
I am successfully displaying the filename and everything but not the share link.
I am getting a NULL.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
BoxItem *item = (BoxItem *)[self.folderItemsArray objectAtIndex:[indexPath row]];
NSLog(#"item type : %# : %# : %# ", item.type, item.name, item.sharedLink);
}
Am using this code.(from sample app)
I am getting results like:
1.item type : file : dummy.pdf : (null)
2. item type : file : presentations-tips.ppt : (null)
I am not getting the sharedlink.
first reaction: may be sharedlinks are not created for those files, So:
I went to my box account and created share links for those files through my desktop.
and rechecked. but got same result.
I need the shared link badly. Please help. Thanks in advance
I got the solution for getting shared link of file. Write following lines of code where you want to get shared link.
BoxFileBlock successfulShare = ^(BoxFile *file)
{
dispatch_sync(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"File Share Successful" message:[NSString stringWithFormat:#"Shared link: %#", [file.sharedLink objectForKey:#"url"]] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
});
};
BoxAPIJSONFailureBlock failedShare = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
{
BOXLog(#"status code: %i", response.statusCode);
BOXLog(#"share response JSON: %#", JSONDictionary);
};
BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] init];
BoxSharedObjectBuilder *sharedBuilder = [[BoxSharedObjectBuilder alloc] init];
sharedBuilder.access = BoxAPISharedObjectAccessOpen;
builder.sharedLink = sharedBuilder;
[[BoxSDK sharedSDK].filesManager editFileWithID:YOUR_FILE.modelID requestBuilder:builder success:successfulShare failure:failedShare];

Simple twitter timeline iOS (only read tweets for no register user)

I want a twitter timeline to be displayed in a View, without the user having to put your twitter account, simplemete read the tweets and hashtag, of the accounts that I have selected during the programming of the app.
Is it possible? Where do I can find info for this?
All I see includes login in twitter.
Thank you.
You can use STTwitterAPIWrapper
Firstly using Twitter you must create an app , because you must use key and secret of your app in the code.
For example :
STTwitterAPIWrapper *twitter = [STTwitterAPIWrapper twitterAPIApplicationOnlyWithConsumerKey:YourTwitterConsumerKey
consumerSecret:YourTwitterConsumerSecret];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *username)
{
NSDictionary *parameters = #{#"q" : #"anyHashTag", #"result_type": #"recent", #"count": #"100"};
[twitter getSearchTweetsWithQuery:parameters successBlock:^(NSDictionary *searchMetadata, NSArray *statuses, NSString *refreshUrl) {
_refreshUrl = refreshUrl;
[self parseJSONString:statuses];
} errorBlock:^(NSError *error) {
//NSLog(#"-- error: %#", error);
}];
} errorBlock:^(NSError *error) {
//NSLog(#"--** error %#", error);
}];

iOS: Canvas URL error when posting to wall

Please see the 29th December update notes at the bottom of the page.
Hi I'm doing maintanance work on someone else's iOS project at work (which is kind of soul destroying because they haven't documented their code).
The problem is that after the user logs in, attempting to share a post to the wall always results in
error 100: "The post's links must direct to the application's connect or canvas URL".
I've searched for the past 2 hours and haven't found any results specifically for iOS (but plenty for wordpress, which didn't help)
Any ideas what might be causing this.
Here's the overseas developer code for posting to the wall:
-(void)uploadPropertyDetailsOnFacebookWall
{
[FBSettings setLoggingBehavior:[NSSet setWithObjects:FBLoggingBehaviorFBRequests, FBLoggingBehaviorFBURLConnections, nil]];
NSString* photoURL = #"";
NSString *strFullPropertyDetailLink=#"";
if (!kIsListOnce) {
photoURL = [currentItem objectForKey:#"Photo1FeaturedURL"];
strFullPropertyDetailLink=[currentItem objectForKey:#"FullDisplayLink"];
}
else {
strFullPropertyDetailLink=[currentItem objectForKey:#"FullDisplayLink"];
NSArray* list = [[currentItem objectForKey:#"objects"] objectForKey:#"img_small"];
;
if ([list count] > 0) {
photoURL = [list objectAtIndex:0];
}
}
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString *strLinkOfApp=(NSString *)[Utils config:KiTunesstoreAppLink]; //strFullPropertyDetailLink,
NSDictionary *postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
strFullPropertyDetailLink, #"link",
photoURL, #"picture",
[Utils config:kTextAgentName], #"name",
strAddress, #"caption",
[currentItem objectForKey:#"Description"], #"description",
nil];
[FBRequestConnection startWithGraphPath:#"me/feed"
parameters:postParams
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSString *alertText;
NSLog(#"%#",error);
if (error) {
NSDictionary *dict=[error userInfo];
NSLog(#"%#",dict);
NSDictionary *dictJSON=[dict objectForKey:#"com.facebook.sdk:ParsedJSONResponseKey"];
NSDictionary *dictBody=[dictJSON objectForKey:#"body"];
NSDictionary *dictError=[dictBody objectForKey:#"error"];
NSString *strCode=[[dictError objectForKey:#"code"] description];
if([strCode isEqualToString:#"200"])
{
alertText = #"You have not authorized the application to perform this publish action";
}else{
alertText = [#"An error ocurred: " stringByAppendingString:error.description];
alertText=[alertText stringByAppendingString: strFullPropertyDetailLink];
}
} else {
alertText = [NSString stringWithFormat:
#"Property details has been successfully shared on your Facebook Wall"];
}
[[[UIAlertView alloc] initWithTitle:#"Result"
message:alertText
delegate:nil
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
// Show the result in an alert
}];
}
Here's the error I keep getting:
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed(com.facebook.sdk error 5.)" UserInfo=0x1d548710 {com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 100;
message = "(#100) The post's links must direct to the application's connect or canvas URL.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:HTTPStatusCode=400}
2013-08-02 12:06:12.806 RealEstate[385:907] {
"com.facebook.sdk:HTTPStatusCode" = 400;
"com.facebook.sdk:ParsedJSONResponseKey" = {
body = {
error = {
code = 100;
message = "(#100) The post's links must direct to the application's connect or canvas URL.";
type = OAuthException;
};
};
code = 400;
};
}
Please help, I have done more research online since my initial posting, and still can't find the answer.
Update Dec 17th:
I am using SDK 3.1.1. I'd like to avoid having to update, as I'm maintaining someone else's code.
Using me/feed, in a fbrequestconnection, any additional paramater aside from "message", crashes the app.
I've also tried linking the app to a test account with settings suggested by other stack overflow users viewable here
I've also disabled post streaming security
Other Questions
Am I missing something in linking up the app to Facebook?
Why won’t it detect that the “link” parameter is the same as the canvas url?
I've been struggling with posting to facebook wall too.
Why don't you use the facebook SDK instead of the API?
There are two ways to post to facebook wall using the SDK
Via Feed Dialog
or
Via Share Dialog
The Feed Dialog is very easy to implement and you can control what you want to post through the parameters you send, the only bad thing is that the parameters are limited.
The Share Dialog uses OpenGraph and requires the user to have the facebook APP installed, you also have to create an action in app developer page in facebook so your app knows what to do with that action.
The good part is that you can share almost all that you want.
I suggest you check the Feed Dialog if you want a simple facebook share, it's the easiest way.
Edit
NSString *message = [NSString stringWithFormat:#"%#%#/%#",domain,TypeName,[object alias]];
// Put together the dialog parameters
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"TITLE", #"description",
message, #"link",
[object image],#"picture",
nil];
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or publishing a story.
//NSLog(#"Error publishing story.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
//NSLog(#"User canceled story publishing.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
// User clicked the Cancel button
//NSLog(#"User canceled story publishing.");
} else {
// User clicked the Share button
NSString *msg = #"Partilhado com sucesso";
//NSLog(#"%#", msg);
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Aviso"
message:msg
delegate:nil
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}
}
}
}];

Resources