gpt4 book ai didi

iphone - 如何使用 ASIHTTPRequest 在 Facebook 上发布带有标签的照片

转载 作者:行者123 更新时间:2023-11-28 17:43:24 25 4
gpt4 key购买 nike

我正在使用 Graph API 和 ASIFormDataRequest 从我的 iPhone 应用程序在 Facebook 上发布一张照片。一切正常(上传的照片带有正确的标题)。当我尝试添加标签时,照片仍在上传,但没有标签。

这是我准备数据的方式

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/photos",userID]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addFile:filePath forKey:@"file"];
[request setPostValue:caption forKey:@"message"];
[request setPostValue:fbManager._facebook.accessToken forKey:@"access_token"];
[request setAllowCompressedResponse:NO];
[request setTimeOutSeconds:60];

//Add tags
NSMutableArray *tagArray=[[NSMutableArray alloc] init];
for(FacebookTag *aTag in aJob.tags) {
NSNumber *_cordX=[NSNumber numberWithFloat:((aTag.x/aJob.image.size.width)*100.0)];
NSNumber *_cordY=[NSNumber numberWithFloat:((aTag.y/aJob.image.size.height)*100.0)];

NSString *cordX=[_cordX stringValue];
NSString *cordY=[_cordY stringValue];

NSMutableDictionary* tag = [NSMutableDictionary dictionaryWithObjectsAndKeys:
aTag.userId, @"to",
cordX, @"x",
cordY, @"y",
nil];
[tagArray addObject:tag];
}

NSData *tagData = [NSKeyedArchiver archivedDataWithRootObject:tagArray];
NSString* tagString = [[NSString alloc] initWithData:tagData encoding:NSUTF8StringEncoding];
[request setPostValue:tagString forKey:@"tags"];

最佳答案

试试这段代码

//上传照片...

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
newPhoto, @"picture", nil];

[self.facebook requestWithGraphPath:@"me/photos" andParams:params
andHttpMethod:@"POST" andDelegate:self];

...

// Response received. Photo upload successful, so add tags
- (void)request:(FBRequest *)request didLoad:(id)result {
if ([request.params objectForKey:@"picture"]) {
// Get photo ID from result
NSString* photoId = (NSString*)[result objectForKey:@"id"];

NSMutableDictionary* params = nil;
for (int i = 0; i < [tagsList count]; i++) {
// tagsList contains user IDs to tag
NSString* uid = (NSString*)[tagsList objectAtIndex:i];
params = [NSMutableDictionary dictionaryWithObjectsAndKeys:uid, @"to",
nil];
NSString* graphUrl = [NSString stringWithFormat:@"%@/tags", [photoId stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
[self.facebook requestWithGraphPath:graphUrl
andParams:params andHttpMethod:@"POST" andDelegate:self];
}
}
...
}

它正在使用 FBGraph API

关于iphone - 如何使用 ASIHTTPRequest 在 Facebook 上发布带有标签的照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7186231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com