Skip to content

Instantly share code, notes, and snippets.

@ekoneil
ekoneil / gist:6813974
Last active December 24, 2015 14:39
[Facebook iOS SDK example] Publish an Open Graph (OG) story that: 1/ uses image staging 2/ creates a custom, user-owned OG object 3/ creates a custom OG action
UIImage* image = [UIImage imageNamed:@"inspiration-2.jpg"]; // image stored in app's resources
// stage an image
[FBRequestConnection startForUploadStagingResourceWithImage:image
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(error) {
NSLog(@"Error staging resource.\n%@", error);
int code = [[[[[error userInfo] objectForKey:@"com.facebook.sdk:ParsedJSONResponseKey"] objectForKey:@"body"] objectForKey:@"error"] objectForKey:@"code"];
if(code == 2500) {
@ekoneil
ekoneil / gist:5208152
Created March 20, 2013 20:29
Post a photo to Facebook using curl
curl -X POST \
"https://graph.facebook.com/{id-of-user-or-album}/photos"
-F "access_token=$T" \
-F "source=@{path-to-file}" \
-F "message=A black box"
@ekoneil
ekoneil / gist:4064293
Created November 13, 2012 06:27
MDD CLLocationManager Code Snippets
CLLocationManagerDelegate
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (strong, nonatomic) FBCacheDescriptor *placeCacheDescriptor;
// Get the CLLocationManager going.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
// We don't want to be notified of small changes in location, preferring to use our
@ekoneil
ekoneil / gist:3912400
Created October 18, 2012 15:02
Creating an FBSession from handleOpenUrl. Workaround for an SDK bug.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// Save the incoming URL to test deep links later.
self.openedURL = url;
// Work around for app link from FB with valid info. If the session is closed, set the valid info (if any) in the cache
if (FBSession.activeSession.state == FBSessionStateCreated || FBSession.activeSession.state == FBSessionStateClosed){
@ekoneil
ekoneil / handleOpenUrl workaround
Created October 18, 2012 15:01
Creating an FBSession from handleOpenUrl. Workaround for an SDK bug.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// Save the incoming URL to test deep links later.
self.openedURL = url;
// Work around for app link from FB with valid info. If the session is closed, set the valid info (if any) in the cache
if (FBSession.activeSession.state == FBSessionStateCreated || FBSession.activeSession.state == FBSessionStateClosed){
@ekoneil
ekoneil / gist:3406258
Created August 20, 2012 18:08
Web Dialogs and the Facebook SDK 3.x for iOS
/*
Requirements:
1/ Manually copy the DeprecatedHeaders folder from the SDK's {install-dir}/FacebookSDK/FacebookSDK.framework/Versions/Current into your project's Supporting Files directory
2/ Instantiate an instance of the Facebook class. This class implements the dialog:andParams:andDelegate method. Example:
self.facebook = [[Facebook alloc] initWithAppId:@"{app-id}" andDelegate:self];
Note: several dialogs from this list: https://developers.facebook.com/docs/reference/dialogs/ are unsupported on iOS / Android touch devices. The following don't work:
1/ add page tab
2/ (add) friends
3/ send
@ekoneil
ekoneil / gist:3287652
Created August 7, 2012 17:37
Enable verbose logging of Facebook API calls
[FBSettings setLoggingBehavior:[[NSSet alloc] initWithArray:@[FBLoggingBehaviorFBRequests,
FBLoggingBehaviorFBURLConnections]]];
@ekoneil
ekoneil / gist:3178821
Created July 25, 2012 21:30
Calling Facebook APIs with the 3.0 SDK
// #1: Graph API: /me
- (void)requestMe {
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *me,
NSError *error) {
if(error) {
[self printError:@"Error requesting /me" error:error];
return;
}
@ekoneil
ekoneil / gist:3106393
Created July 13, 2012 18:10
FB URL Templates
1/ Desktop web Auth Dialog
GET https://www.facebook.com/dialog/permissions.request?app_id={fb-app-id}&display=page&next={redirect-url}&response_type=token&fbconnect=1&perms={permissions}
2/ Mobile web Auth Dialog
GET https://m.facebook.com/dialog/permissions.request?app_id={fb-app-id}&display=touch&next={redirect-url}&response_type=token&fbconnect=1&perms={permissions}
3/ Extend access token
@ekoneil
ekoneil / gist:1419286
Created December 1, 2011 19:42
Configuring privacy for stories published to Facebook
#!/bin/bash
# Works for stream.publish and open graph actions
# Only Me privacy
# -F "privacy={'value':'SELF'}" \
# Subset of friends privacy
# -F "privacy={'value':'CUSTOM', 'friends':'SOME_FRIENDS', 'allow': 'uid-1,uid-2'}" \