[self.ACAstore requestAccessToAccountsWithType:twitterType withCompletionHandler:^(BOOL granted, NSError *error) {
self.bPermissionToAccessStoreGranted=granted;
[self vContinue];
// Handle any error state here as you wish
}];
The result of granted is simply false. I want users to get get asked first.
The possible cause is that the iPhone has no twitter accounts. In which case I want to display a twitter login page so user can sign up.
[self.ACAstore requestAccessToAccountsWithType:twitterType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted)
{
[self vContinue];
}
else {
// Handle any error state here as you wish
}
}];
Do you want this?
Related
This seems to be age old question with no specific answers or solutions for it. I had my application whitelisted from twitter. Done all the things. Checked the request email from user box and used the following code
[[Twitter sharedInstance] startWithConsumerKey:#"FabricKey" consumerSecret:#"FabricSecretKey"];
if ([[Twitter sharedInstance] session]) {
TWTRShareEmailViewController *shareEmailViewController =
[[TWTRShareEmailViewController alloc]
initWithCompletion:^(NSString *email, NSError *error) {
NSLog(#"Email %# | Error: %#", email, error);
}];
[self presentViewController:shareEmailViewController
animated:YES
completion:nil];
But still it is returning null. Why is this?? I even created the application in twitter developer portal. Please help me. Is twitter trying to be more over secure?? It is just pissing me out......
I am trying to request access to my facebook account. The first time I ran this it went well and I saw the popup requesting permissions. The popup asked me to allow or deny. I chose to deny because I wanted to test that use case. Now I cannot figure out how to get it to allow access again. I have deleted the app from my facebook account and deleted my facebook account from my mac. I've also tried adding the property
#"auth_type": #"rerequest"
to the options dictionary. I get the same result no matter what.
As mentioned in the title, the error is nil and granted is False.
Thanks in advance.
ACAccountType* accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary* options = #{
ACFacebookAppIdKey: [[NSBundle mainBundle] objectForInfoDictionaryKey:#"FacebookAppID"],
ACFacebookPermissionsKey: #[#"public_profile", #"email", #"user_friends"],
};
[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError* error)
{
if (granted)
{
ACAccount* account = [[accountStore accountsWithAccountType:accountType] lastObject];
macFacebookAccount = account;
}
else
{
NSLog(#"%#", error);
}
}];
I solved this: Facebook permission settings for an app are located under System Preferences > Security and Privacy. From there just click facebook and check the box next to your app
I've been looking through the open grpah reference docs, and can't seem to find a good example related to SLRequest regarding users and whether they like a certain page or not. I don't want to iterate through their entire list of likes.
I was looking at https://developers.facebook.com/docs/graph-api/reference/user/likes/ but I'm not sure how to work with it and SLRequest, I've done the following but I'm receiving the following response:
Received Response: {"error":{"message":"An active access token must be used to query
information about the current
user.","type":"OAuthException","code":2500}}
Thing is all of this code only runs if the suer has previously authenticated and granted permission, and so it must have found an account, yet I still get this respond. Could it be that I'm not requesting a specific permission? I've requested, "email, public_actions, user_likes and public_stream".
BTW I do have another view controller where I ask for these permissions (except user_likes), and everything works in that one. Is there anything that I'm missing here? Thanks!
NSURL *feedURL = [NSURL URLWithString:#"https://graph.facebook.com/me/likes/{MYPAGEID}"];
[SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:feedURL parameters:nil];
[updateFeedRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (responseData ) {
NSLog(#"Received Response: %#", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
if (urlResponse.statusCode >= 200 && urlResponse.statusCode < 300) {
NSLog(#"Successful Connection");
} else {
}
} else {
NSLog(#"No response.");
}
}];
The error that you are getting is received when you try to make calls like /me but no user is currently logged-in to your app or the user has already logged-out of the app.
I'm not sure of your complete flow of the app but you can try this to validate your access token and call- you have the access token right? so, with your current API call just add an extra parameter access_token with its value.
I'm trying to acquire the accessToken value from Twitter for using it in my app (I need to use API v1.1's Authentication Model for GET statuses/user_timeline); I have registered my app on api.twitter.com, imported the AFOAuth1Client classes in the project, and this is the simple code:
- (void)viewDidLoad
{
self.twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:
[NSURL URLWithString:#"https://api.twitter.com/"] key:#"MYKEY" secret:#"MYSECRETKEY"];
AFOAuth1Token *accessToken;
[self.twitterClient acquireOAuthAccessTokenWithPath:#"oauth/request_token" requestToken:accessToken accessMethod:#"GET" success:^(AFOAuth1Token *accessToken) { // I have tried also accessMethod: #"POST"
NSLog(#"Success: %#", accessToken);
} failure:^(NSError *error) {
NSLog(#"Error: %#", error);
}];
}
Unluckly XCode give me this error:
Error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 401" UserInfo=0x79a14f0 {NSLocalizedRecoverySuggestion=Failed to validate oauth signature and token, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7956390>
What is wrong here? DO i need to REGISTER app on api.twitter.com? Is it the right way, or, what is the simpler way to Get statuses/user_timeline using API v1.1's Twitter Authentication Model in iOS? Thank you!
EDIT: possible waypoint?
1) register a new app on dev.twitter.com
2) in OAuth settings, read Consumer key and Consumer secret
3) set default app access type to read? or read/write? ask for access tokens? use this values in.... ?
It's been a few days since Twitter added an application only mode. In this mode, you can access specific API endpoints without user's context, ie. your users don't have to authenticate. Only the application does authenticate once in a while to get a "bearer token" which is then sent in every request.
The following code gets a bearer token and then retrieves the public timeline for #barackobama.
STTwitterAPI *twitter = [STTwitterAPI twitterAPIApplicationOnlyWithConsumerKey:#""
consumerSecret:#""];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {
NSLog(#"Access granted with %#", bearerToken);
[twitter getUserTimelineWithScreenName:#"barackobama" successBlock:^(NSArray *statuses) {
NSLog(#"-- statuses: %#", statuses);
} errorBlock:^(NSError *error) {
NSLog(#"-- error: %#", error);
}];
} errorBlock:^(NSError *error) {
NSLog(#"-- error %#", error);
}];
See STTwitter iOS demo project for a working example (use you own consumer key / secret).
If you have your own consumer tokens, you can use the STTwitter library I wrote.
STTwitterAPI *twitter =
[STTwitterAPI twitterAPIWithOAuthConsumerName:#""
consumerKey:#"your_key"
consumerSecret:#"your_secret"
username:#"username"
password:#"password"];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
NSLog(#"Access granted for %#", username);
[twitter getUserTimelineWithScreenName:#"barackobama"
successBlock:^(NSArray *statuses) {
NSLog(#"-- statuses: %#", statuses);
} errorBlock:^(NSError *error) {
NSLog(#"-- error: %#", error);
}];
} errorBlock:^(NSError *error) {
NSLog(#"-- error %#", error);
}];
If your tokens are not 'xAuth' enabled, you'll have to use a PIN. STTwitter provides simple asynchronous block-based methods to ask the user. You can also choose to automate the PIN retrieval, see STTwitterDemo -[AppDelegate guessPIN:] for an automated process.
STTwitter is simple for use . Also I added example that you can get public twitter timeline
A quick question about the Facebook SDK for iOS. I'm trying to implement the functionality for a user to grant my app access to extended permissions.
While the code works fine when the user accepts the extended permission request (from the Facebook iOS app the user gets redirected to), I'm having trouble detecting when the user has returned to the app while having neither accepted the permissions, or clicking cancel then returning to the app.
If I click 'Cancel' and multitask back into the app, there is nothing logged and nothing shown on-screen. When I try to re-authorize again, the Facebook SDK throws an exception:
FBSession: It is not valid to reauthorize while a previous reauthorize call has not yet completed.
While I can catch the exception, it still doesn't help as I can't figure out how to stop the previous call in order to allow the user to try to re-authorize again.
Here's the code I'm using at the moment:
#try {
[[FBSession activeSession] reauthorizeWithPermissions:[self requiredPermissions]
behavior:FBSessionLoginBehaviorWithFallbackToWebView
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
[self fetchUserPermissionsWithCompletionHandler:^(BOOL extendedGranted) {
if (extendedGranted) {
[self setCanPostToActivityStream:YES];
}
}];
}
else {
NSLog(#"%#", [error localizedDescription]);
}
}];
}
#catch (NSException *exception) {
NSLog(#"%#", exception);
}
Now, the issue is not with the code above - the code works fine. The issue I'm having, again, is cancelling the previous re-authorize call when the user doesn't return to the app successfully after allowing permissions. The Facebook SDK as it is doesn't seem to alert the app of this situation in any way.
From your App's delegate, when - (void)applicationDidBecomeActive:(UIApplication*)application is invoked, you need to make a call to the active session's handleDidBecomeActive method. Once you do that, the completion handler associated with your reauthorizeWithPublishPermissions call will be invoked, and will provide the appropriate error.
- (void)applicationDidBecomeActive:(UIApplication*)application
{
[[FBSession activeSession] handleDidBecomeActive];
}
What you should see coming back from the SDK is an error from the reauthorize completion handler.
{
"com.facebook.sdk:ErrorLoginFailedReason" = "com.facebook.sdk:ErrorReauthorizeFailedReasonUserCancelled";
}
I tested something similar with the following setup: Xcode 4.5, iOS 5, Authorize against m.facebook.com. After an initial authorization I put code to hit reauthorize, then clicked Cancel and got this error.
[FBSession.activeSession
reauthorizeWithPublishPermissions:
[NSArray arrayWithObject:#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// Success case
} else {
// Check the error, info
// [[error userInfo] objectForKey:#"com.facebook.sdk:ErrorLoginFailedReason"]
}
}];
If you are not seeing this then it is a bug and you may want to file it with Facebook.