我想使用我的 AppID 在 facebook 上分享我的图像。所以我可以在 facebook 上看到它via App
。它工作正常,直到 iOS 5。但不是在 iOS 6。
如果我使用的是SLComposeViewController
,那么我可以共享图像,但显示的是“通过 iOS”而不是“通过应用程序”。所以我已经查看了它的代码并应用了它,但它没有共享图像。请检查代码是否有任何问题并进行更正。
facebookaccount = [[ACAccountStore alloc] init];
ACAccountType *facebookaccountType = [facebookaccount accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierFacebook];
// Specify App ID and permissions
NSDictionary *options = @{ ACFacebookAppIdKey: @"xxxxxxxxxxxxx", ACFacebookPermissionsKey: @[@"publish_stream"], ACFacebookAudienceKey: ACFacebookAudienceFriends };
[facebookaccount requestAccessToAccountsWithType:facebookaccountType options:options completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray *accountsArray = [facebookaccount accountsWithAccountType:facebookaccountType];
facebookAccount = [[accountsArray lastObject] retain];
NSLog(@" Account :::: %@", facebookAccount);
} else {
NSLog(@" Error :::: %@", error.description);
}}];
NSDictionary *parameters = @{@"message" : @""};
NSString *link = [NSString stringWithFormat:@"%simages/%@",ServerPath,[images objectAtIndex:imageNO]];
NSURL *url = [NSURL URLWithString:link];
NSData *data = [NSData dataWithContentsOfURL:url];
CGFloat compression = 1.0f;
CGFloat maxCompression = 0.0f;
int maxFileSize = 150*224;
UIImage *img1 = [[UIImage alloc] initWithData:data];
NSData *imageData = UIImageJPEGRepresentation(img1, compression);
while ([imageData length] > maxFileSize && compression > maxCompression){
compression -= 0.1;
imageData = UIImageJPEGRepresentation(img1, compression);
}
UIImage *img = [[UIImage alloc] initWithData:imageData];
NSLog(@"Image ::: %@", img);
NSData *myImageData = UIImagePNGRepresentation(img);
NSLog(@" Image Data ::: %@", myImageData);
NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me"];
SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:requestURL parameters:parameters];
[facebookRequest addMultipartData:myImageData withName:@"source" type:@"multipart/form-data" filename:nil];
NSLog(@"Request Account :::: %@", facebookAccount);
facebookRequest.account = facebookAccount;
[facebookRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSLog(@"Done with Facebook.......");
if (!error) {
NSDictionary *list = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@" Dictionary ::: %@", list);
} else {
NSLog(@" Error :::: %@", error.description);
}}];
我在字典日志中得到空值。
可能是什么问题?谢谢你。