SLRequest gives Parse Error: Expected ] - objective-c

I'm writing a Facebook Parser for iOS6. Yesterday, I made a test project with only the parser. This worked fine. When I want to implement the parser in my bigger project (with exactly the same method code), a "Parse Error: Expected ]" is given. The imports for Social and Accounts are set.
This is the line that gives the error:
SLRequest *retrieveWall = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:newsFeed parameters:nil];
This is the full method:
-(void)fetchFacebookFrom:(NSString*)userID withAppKey:(NSString*)appKey
{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = #{
#"ACFacebookAppIdKey" : appKey,
#"ACFacebookPermissionsKey" : #[#"email"],
#"ACFacebookAudienceKey" : ACFacebookAudienceEveryone
};
[accountStore requestAccessToAccountsWithType:accountType
options:options completion:^(BOOL granted, NSError *error) {
if(granted)
{
NSArray *arrayOfAccounts = [accountStore
accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
ACAccount *facebookAccount = [arrayOfAccounts lastObject];
NSURL *newsFeed = [NSURL URLWithString:#"https://graph.facebook.com/12345678901/feed"];
SLRequest *retrieveWall = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:newsFeed parameters:nil];
retrieveWall.account = facebookAccount;
[retrieveWall performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (error)
{
NSLog(#"Error: %#", [error localizedDescription]);
}
else
{
// The output of the request is placed in the log.
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:nil];
NSArray *statuses = [jsonResponse objectForKey:#"data"];
}
}];
}
}
else
{
NSLog(#"Not granted");
}
}];
}
The error specificly points to "URL" in the method call..
This stupid error is driving me crazy for 3 hours already. I restarted XCode, cleaned the project and rebooted my Mac. Who sees the error?
EDIT: It seems that this particular code is not the problem. I added core data too, which has some functions with URL in method names.
Every function with URL in the method name now gives a Parse Error and points to "URL". Getting closer to the problem, but still not there!

We defined URL somewhere in a header file. Removing this fixed it. Thanks for thinking about a solution!

Related

Why is my AFNetworking API call result in an error?

I come from a Swift background; therefore, am used to Alamofire. I am trying to learn Objective-C and have been plying with AFNetworking.
The following is a simple method that calls the Yelp search API to find business in the vicinity.
- (void) getBusinesses: (NSString *) usingToken{
NSString *starbucks = #"Starbucks";
NSString *latitude = #""; //enter latitude
NSString *longitude = #""; //enter longitude
NSString *URLString = [NSString stringWithFormat:#"https://api.yelp.com/v3/businesses/search?term=%#&latitude=%#&longitude=%#", starbucks, latitude, longitude];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
AFHTTPRequestSerializer *request = [[AFHTTPRequestSerializer alloc] requestWithMethod:#"GET" URLString:URLString parameters:nil error:nil];
NSString *bearerToken = [NSString stringWithFormat: #"Bearer %#", usingToken];
[request setValue: bearerToken forHTTPHeaderField:#"Authorization"];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error){
if (error){
NSLog(#"*** Failed!");
} else {
NSLog(#"*** Succeeded!");
}
}];
dataTask.resume;
}
When running this code I get the following error:
Incorrect NSStringEncoding value 0x0000 detected. Assuming NSASCIIStringEncoding. Will stop this compatibility mapping behavior in the near future.
I have tested the above Yelp URL with my valid access token on Postman and it works perfectly.
If someone could point me in the right direction to figure out what is going on I'd appreciate it!
P.S. this is the documentation for the Yelp search endpoint

Twitter Streaming Endpoint not working with SLRequest object

I am trying to pull data from the Twitter Streaming API using the SLRequest class.
When I use the endpoint and parameters documented in the code below the program "hangs"
and no JSON data is printed. I am using an endpoint based on an example from the twitter dev
website https://dev.twitter.com/docs/streaming-apis/parameters#with I am requesting
tweets at a certain location.
When I use this code to query my timeline using the REST API (the code and request is included but
commented out) the program does not hang and I get a valid response.
Is there something else in the code that I need to implement to access the data using the streaming API? What additional modifications or changes need to be made?
ACAccountStore * accountStore = [[ACAccountStore alloc] init];
ACAccountType * twitterAccountType =
[accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Ask the user permission to access his account
[accountStore requestAccessToAccountsWithType:twitterAccountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted == NO) {
NSLog(#"-- error: %#", [error localizedDescription]);
}
if (granted == YES){
/***************** Create request using REST API*********************
***************** This URL is functional and returns valid data *****
NSURL * url = [NSURL URLWithString:#"https://userstream.twitter.com/1.1/user.json"];
SLRequest * request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:#{#"screen_name": #"your_twitter_id"}];
***************************************************************/
// Create request using Streaming API Endpoint
NSURL * url = [NSURL URLWithString:#"https://stream.twitter.com/1.1/statuses/filter.json"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:#"track" forKey:#"twitter&"];
[params setObject:#"locations" forKey:#"-122.75,36.8,-121.75,37.8"];
SLRequest * request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:url parameters:params];
NSArray * twitterAccounts = [accountStore accountsWithAccountType:twitterAccountType];
if ([twitterAccounts count] == 0) {
(NSLog(#"-- no accounts available"));
} else if ([twitterAccounts count] >0){
[request setAccount:[twitterAccounts lastObject]];
NSLog([request.account description]);
NSLog(#"Twitter handler of user is %#", request.account.username);
// Execute the request
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSError * jsonError = nil;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&jsonError];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
// NSLog(#"-- json Data is %#", json);
NSLog([json description]);
}];
}];
}
}
}];
SLRequest doesn't play well with the streaming API.
Here is how to do with STTwitter:
self.twitter = [STTwitterAPI twitterAPIOSWithAccount:account];
[_twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
NSLog(#"-- access granted for %#", username);
[_twitter postStatusesFilterUserIDs:nil
keywordsToTrack:#[#"twitter"]
locationBoundingBoxes:#[#"-122.75,36.8,-121.75,37.8"]
delimited:nil
stallWarnings:nil
progressBlock:^(id response) {
NSLog(#"-- %#", response);
} stallWarningBlock:^(NSString *code, NSString *message, NSUInteger percentFull) {
NSLog(#"-- stall warning");
} errorBlock:^(NSError *error) {
NSLog(#"-- %#", [error localizedDescription]);
}];
} errorBlock:^(NSError *error) {
NSLog(#"-- %#", [error localizedDescription]);
}];
Internally, STTwitter builds a NSURLConnection instance with the request from -[SLRequest preparedURLRequest]. You can replicate this trick in your code if you wish.

can not get user info after doing authentication,facebookSDK, ios

I am trying to authenticate using facebook account by following
- (IBAction)logInByFaceBook:(id)sender {
NSLog(#"appDelegate.session.isOpen = %#",appDelegate.session.isOpen == 0 ? #"NO" : #"YES");
FBSessionLoginBehavior behavior = FBSessionLoginBehaviorForcingWebView;
appDelegate.session = [[FBSession alloc] init];
[appDelegate.session openWithBehavior:behavior
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:[NSNumber numberWithBool:YES] forKey:#"didLogIn"];
data = [[SavedData alloc] initLogInInfo:dict];
[data saveLogInInfoToDisk];
if (session.isOpen) {
FBRequest *me = [FBRequest requestForMe];
NSLog(#"me is %#",[me description]);
[me startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *my, NSError *error) {
NSLog(#"my is %#",[my description]);
}
];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
];
}
However, i cant not get my username back and the console is displaying
Error: HTTP status code: 400
my is (null)
By looking up this documentation, 400 means Invalid email address..... and my is null so that I can no extract the username at all.....
I dont know why this happens...I try with the same email address with facebookSDK sample code and it works properly...
Getting lost now....Can somebody point out what I am doing wrong or missing something.

Objective-C Twitter API 150 Requests

I am trying to fetch tweets from twitter using an NSURLConnection, and I keep hitting the maximum number of requests per hour (150). I switched to using the authenticated way of fetching tweets, like below, but still hit the maximum API calls - 150. How am I able to make more than 150 twitter requests per device?
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType =
[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request permission from the user to access the available Twitter accounts
[store requestAccessToAccountsWithType:twitterAccountType
withCompletionHandler:^(BOOL granted, NSError *error) {
if (!granted) {
// The user rejected your request
NSLog(#"User rejected access to the account.");
}
else {
// Grab the available accounts
NSArray *twitterAccounts =
[store accountsWithAccountType:twitterAccountType];
if ([twitterAccounts count] > 0) {
// Use the first account for simplicity
ACAccount *account = [twitterAccounts objectAtIndex:0];
// Now make an authenticated request to our endpoint
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:#"1" forKey:#"include_entities"];
// The endpoint that we wish to call
NSURL *url =
[NSURL
URLWithString:#"https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=%#&count=5",someTwitterUserName];
// Build the request with our parameter
TWRequest *request =
[[TWRequest alloc] initWithURL:url
parameters:params
requestMethod:TWRequestMethodGET];
// Attach the account object to this request
[request setAccount:account];
[request performRequestWithHandler:
^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (!responseData) {
// inspect the contents of error
NSLog(#"%#", error);
}
else {
NSError *jsonError;
NSArray *timeline =
[NSJSONSerialization
JSONObjectWithData:responseData
options:NSJSONReadingMutableLeaves
error:&jsonError];
if (timeline) {
// at this point, we have an object that we can parse and grab tweet information from
NSLog(#"%#", timeline);
}
else {
// inspect the contents of jsonError
NSLog(#"%#", jsonError);
}
}
}];
} // if ([twitterAccounts count] > 0)
} // if (granted)
}];
Try see at this post
solution
Problem in your twitter app, who have a limit at default

Twitter integration and iOS5: semantic and parsing issues

I was using some of Apple's example code to write the Twitter integration for my app.
However, I get a whopping amount of errors (mostly being Semantic and parse errors).
How can this be solved?
-(IBAction)TWButton:(id)sender {
ACAccountStore *accountstore = [[ACAccountStore alloc] init];
//Make sure to retrive twitter accounts
ACAccountType *accountType = [accountstore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountstore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if (granted) [{
NSArray *accountsArray = [accountstore accountsWithAccountType:accountType];
if ([accountsArray count] > 0) {
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:#"http://api.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:[#"Tweeted from iBrowser" forKey:#"status"] requestMethod:TWRequestMethodPOST];
[postRequest setAccount:twitterAccount];
[postRequest preformRequestWithHandeler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:#"HTTP response status: %i", [urlResponse statusCode]];
[self preformSelectorOnMainThread:#selector(displaytext:) withObject:output waitUntilDone:NO];
}];
}
}];
}
//Now lets see if we can actually tweet
-(void)canTweetStatus {
if ([TWTweetComposeViewController canSendTweet]) {
self.TWButton.enabled = YES
self.TWButton.alpha = 1.0f;
}else{
self.TWButton.enabled = NO
self.TWButton.alpha = 0.5f;
}
}
The first error I see is easy to get rid of.
Objective C convention is to make the first letters of each method name lower case.
Use makeKeyAndVisible in your AppDelegate.m
The other errors we'd probably need to see where (in your code) the errors are being thrown, not just what kind of errors.