iOS - Unable to Upload media with Twitter/Fabric New SDK

后端 未结 4 1722
面向向阳花
面向向阳花 2021-02-06 12:52

I want to post a photo to twitter from my iOS app. I can post a tweet without media but when i am trying to attach media it throws an error.

I am following twitter docu

4条回答
  •  忘了有多久
    2021-02-06 13:38

    Sharing the swift 2.2 (Xcoe 7.3.2) code if anyone is still looking for help.

     let client = TWTRAPIClient.init(userID:)
    let imgData =  UIImageJPEGRepresentation(UIImage(named:"Home")!, 0.7)
        client.uploadMedia(imgData!, contentType: "image/jpeg", completion: {(media_ids,error) in
    
            if error == nil{
                //prints the media_ids in String. 
          //Pass them into the params of status update params ["media_ids":]
                print(media_ids)
            }
            else{
                print(error?.localizedDescription)
            }
        })
    

    To Send with status update.

       let request = client.URLRequestWithMethod("POST", URL: "https://api.twitter.com/1.1/statuses/update.json", parameters: ["status":"Hello World","media_ids":], error: nil)
    
        client.sendTwitterRequest(request, completion: {
            (response,data,error)in
            if error == nil {
                print(data)
    
            }
            else{
                print("Error")
            }
        })
    }
    

提交回复
热议问题