2014-06-19 3 views
6

나는 페이스 북에 이미지와 함께 위치를 공유하려고합니다. 성공적으로 이미지를 공유했지만 위치를 공유 할 수 없습니다. 아래는 공유 이미지에 대한 나의 코드입니다.IOS에서 페이스 북에 이미지가있는 위치를 게시하는 방법은 무엇입니까?

UIImage *facebookImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imagesURL,str]]]]; 
NSMutableDictionary* params = [[NSMutableDictionary alloc] init]; 
[params setObject:@"New Happening created on the HappenShare mobile app." forKey:@"message"]; 
[params setObject:facebookImage forKey:@"picture"]; 
[FBRequestConnection startWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection,id result,NSError *error) 
{ 
    if (error) 
    { 
     NSLog(@"error : %@",error); 
    } 
    else 
    { 
     NSLog(@"Result : %@",result); 
    } 
}]; 

위의 코드에 어떤 매개 변수를 추가해야합니까? 공유 위치가 어떻게 생겼는지 더 잘 이해하기 위해 이미지를 첨부하고 있습니다. 아래 이미지는 텍스트가있는 이미지가지도에 위치를 나타내는 방법을 보여줍니다. 저에게 해결책을 제안 해주십시오. enter image description here

답변

2
"메시지"와 함께

하고 또한 필요 "장소"ID를 : 여기에 설명 된대로

, 당신은 그의 FB 아이폰 OS SDK의 PlacePicker UI 구성 요소를 사용, https://developers.facebook.com/docs/graph-api/reference/v2.0/user/photos/#publish iOS에서

를 참조하십시오 param으로 게시 할 수 있습니다.

장소/위치를 게시 할 수 있도록 "publish_actions"를 요청하십시오. 다음은

내가 사용했던 코드입니다 : 당신은 또한 개발자 페이지에 주어진 "관리자/테스터"계정을 사용하여이 문제를 확인할 수 있습니다

NSMutableDictionary *params = [NSMutableDictionary dictionary]; 
        [params setObject:@"Hello World" forKey:@"message"]; 
        [params setObject:@"110503255682430"/*sample place id*/ forKey:@"place"]; 
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/feed" parameters:params HTTPMethod:@"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
         NSLog(@"result %@",result); 
         NSLog(@"error %@",error); 
}]; 

-> 당신의 응용 프로그램 -> 역할. 더 나은 연습 사용 그래프 탐색기 : 코드 아래 https://developers.facebook.com/tools/explorer/108895529478793?method=POST&path=me%2Ffeed%3F&version=v2.5&message=Hello%20world&place=110503255682430

이 위치 근처에서 ID를 얻기에서 당신을 도울 수 있습니다

NSMutableDictionary *params2 = [NSMutableDictionary dictionaryWithCapacity:4L]; 
    [params2 setObject:[NSString stringWithFormat:@"%@,%@",YourLocation latitude,YourLocation longitude] forKey:@"center"]; //Hard code coordinates for test 
    [params2 setObject:@"place" forKey:@"type"]; 
    [params2 setObject:@"100"/*meters*/ forKey:@"distance"]; 

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/search" parameters:params2 HTTPMethod:@"GET"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
        NSLog(@"RESPONSE!!! /search"); 
}]; 

또는

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/search?type=place&center=YourLocationLat,YourLocationLong&distance=500" parameters:nil HTTPMethod:@"GET"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
        NSLog(@"result %@",result); 
}]; 

가 당신을 도움이되기를 바랍니다 ..

0

@Satish 대답의 Swift 3.2 버전.

let photo = Photo(image: img, userGenerated: true) 
var content = PhotoShareContent() 
content.photos = [photo] 
content.placeId = id //Facebook placeId 
let sharer = GraphSharer(content: content) 
sharer.failsOnInvalidData = true 

do { 
    try sharer.share() 
} catch { 
    print("errorrrr") 
} 

sharer.completion = { FBresult in 

    switch FBresult { 
    case .failed(let error): 
     print(error) 
     break 
    case .success(_): 
     //code 
     break 
    default: 
     break 
    } 
} 
placeId

부착 페이스 북 공유를위한
func getPlaceId() { 

    let locManager = CLLocationManager() 
    locManager.requestWhenInUseAuthorization() 

    var currentLocation = CLLocation() 

    if(CLLocationManager.authorizationStatus() == .authorizedWhenInUse || 
     CLLocationManager.authorizationStatus() == .authorizedAlways) { 

     currentLocation = locManager.location! 

     let param = ["center":"\(currentLocation.coordinate.latitude),\(currentLocation.coordinate.longitude)","type":"place","distance":"100"] 

     FBSDKGraphRequest(graphPath: "/search", parameters: param).start(completionHandler: { (connection, result, error) -> Void in 
      if (error == nil) { 
       guard let data = result as? NSDictionary else { 
        return 
       } 
       guard let arrPlaceIDs = data.value(forKey: "data") as? [NSDictionary] else { 
        return 
       } 
       guard let firstPlace = arrPlaceIDs.first else { 
        return 
       } 
       //First facebook place id. 
       print(firstPlace.value(forKey: "id") as! String) 
      } else { 
       print(error?.localizedDescription ?? "error") 
      } 
     }) 
    } 
} 

관련 문제