2017-05-15 6 views
0

아래 코드는 작동하지만 트위터에 게시되지만 세 개의 이미지가 전송 되더라도 하나의 이미지 만 계정에 게시합니다.Tweetsharp Twitter API - 복수 이미지 게시

이들은 동영상이나 애니메이션 GIF가 아닌 jpg 또는 png 파일입니다.

모든 아이디어를 얻을 수 있습니다.

Dim service = New TwitterService(key, secret) 
    service.AuthenticateWith(token, tokenSecret) 

    Dim opt As New SendTweetWithMediaOptions 

    Dim images As New Dictionary(Of String, IO.Stream) 
    Dim myStream As FileStream 

    If Len(ImgName1) > 0 Then 
     myStream = New FileStream(ImgName1, FileMode.Open) 
     images.Add("1", myStream) 
    End If 
    If Len(ImgName2) > 0 Then 
     myStream = New FileStream(ImgName2, FileMode.Open) 
     images.Add("2", myStream) 
    End If 
    If Len(ImgName3) > 0 Then 
     myStream = New FileStream(ImgName3, FileMode.Open) 
     images.Add("3", myStream) 
    End If 

    opt.Status = TweetText 
    opt.Images = images 

    Dim TwitterStatus = service.SendTweetWithMedia(opt) 

답변

0

여러 이미지를 지원하지 않는 TweetSharp 방법에 의해 호출되는 API 엔드 포인트는 (; https://dev.twitter.com/rest/reference/post/statuses/update_with_media 내가 이제까지했던 생각하지 않지만, 어느 쪽이든 현재 문서는 아무 말 없음).

UploadMedia 끝점을 사용하여 이미지를 업로드하고 각각의 ID를 캡처 한 다음 ID 목록을 사용하여 트윗을 전송하면됩니다.

사용중인 TweetSharp의 변형이 확실하지 않습니다. 공식/원래의 API는 Nuget 패키지의 버그를 알고 있으며, repo의 소스에는 고정 API가 있지만 최신 API 지원이 부족합니다.

TweetMoaSharp (대부분 내게 유지)를 시도해 볼 수 있습니다. 새로운 엔드 포인트를 지원한다고 생각합니다. (하지만 보았으므로 오래되었습니다.) Nigget에는 대체품이 있고 그 주변에는 떠있는 몇 가지 다른 것들이 있습니다.

+0

감사합니다. 몇 시간 동안 온라인 검색을 한 후에도 코드와 같지 않지만 API와 동일한 이유가 있습니다. TweetMoaSharp를 시도했지만 이미지를 먼저 업로드하고 ID를 가져 오는 도움말 예제를 찾을 수 없습니다. 나는 TweetInvi와 함께 그것을 가지고있다. 건배. –

1

나는 그것이 (Nuget를 통해 설치) TweetInvi https://github.com/linvi/tweetinvi를 사용하여 작업을 진행하는 데 사용되는 코드는 다음과 같습니다 응답에 대한

(Imports Tweetinvi) 


    Auth.SetUserCredentials(key, secret, token, tokenSecret) 

    Dim params As New Tweetinvi.Parameters.PublishTweetOptionalParameters() 
    params.Medias = New List(Of Models.IMedia) 
    Dim MediaIDs As String = String.Empty 

    Dim ids As New List(Of Long) 

    If Len(ImgName1) > 0 Then 
     Dim imgFile1 As Byte() = System.IO.File.ReadAllBytes(ImgName1) 
     Dim myMedia1 = Upload.UploadImage(imgFile1) 
     ids.Add(myMedia1.MediaId) 
     imgFile1 = Nothing 
    End If 
    If Len(ImgName2) > 0 Then 
     Dim imgFile2 As Byte() = System.IO.File.ReadAllBytes(ImgName2) 
     Dim myMedia2 = Upload.UploadImage(imgFile2) 
     ids.Add(myMedia2.MediaId) 
     imgFile2 = Nothing 
    End If 
    If Len(ImgName3) > 0 Then 
     Dim imgFile3 As Byte() = System.IO.File.ReadAllBytes(ImgName3) 
     Dim myMedia3 = Upload.UploadImage(imgFile3) 
     ids.Add(myMedia3.MediaId) 
     imgFile3 = Nothing 
    End If 

    params.MediaIds = ids 

    Dim myTweet = Tweet.PublishTweet("blah, blah, blah", params)