Media Best Practices | Docs | Twitter Developer Platform

文章推薦指數: 80 %
投票人數:10人

Supported image media types: JPG, PNG, GIF, WEBP; Image size <= 5 MB, animated GIF size <= 15 MB. The file size limit above is enforced by the media upload ... Uploadmedia Overview Guides APIreference Guidescontents MediaBestPractices Chunkedmediaupload ThereareafewimportantconceptstounderstandwhenusingthePOSTmedia/uploadendpoint.UploadingmediawithOAuthcanbeabittricky,sowe’veoutlinedsomethingstokeepinmind,aswellasaworkingsampleofhowtousethisendpointhere. Keepinmind BecausethemethodusesmultipartPOST,OAuthishandleddifferently.POSTorquerystringparametersarenotusedwhencalculatinganOAuthsignaturebasestringorsignature.Onlytheoauth_*parametersareused. Youmayattachupto4photos,1animatedGIFor1videoinaTweet. Theimagepassedshouldbetherawbinaryoftheimageorbinarybase64encoded,noneedtootherwiseencodeorescapethecontentsaslongastheContent-Typeissetappropriately(whenindoubt:application/octet-stream). Whenpostingbase64encodedimages,besuretosetthe“Content-Transfer-Encoding:base64”ontheimagepartofthemessage. Multi-partmessageboundariesmustbeontheirownlineandterminatedbyaCRLF. ForworkingexamplesofhowtoPOSTusingthisendpoint,werecommendtestingwithtwurl.Also,takealookattheTwitterLibrariesavailable,includingthelarge-video-upload-python codesample. Usethemedia_id_stringprovidedintheAPIresponseforJavascriptandanyotherlanguagesthatcannotaccuratelyrepresentalonginteger.   MediaCategories TheMediaCategoryparameterdefinestheusecaseofthemediafiletobeuploaded,andcanaffectfilesizelimitsorotherconstraintsenforcedformediauploads.It’simportanttousethecorrectmediacategorywhenuploadingmediatoavoidproblemswhentryingtousethemedia.ItisanoptionalvaluepassedintheINITrequestaspartoftheuploadflow.Ifmediacategoryisnotspecified,theuploadedmediaisassumedtobeaTweetmedia(image,video,orGIF),dependingonthecontenttype. Themostcommonmediacategoriesareasfollows: TweetImage TweetVideo TweetGif DmImage DmVideo DmGif Subtitles IfyouareanAdsAPIpartnerpleaserefertothesedocsformoreinformationonrecommendedmediacategoryforpromotedvideo. Imagespecificationsandrecommendations Imagefilesmustmeetallofthefollowingcriteria: Supportedimagemediatypes:JPG,PNG,GIF,WEBP Imagesize<=5MB,animatedGIFsize<=15MB Thefilesizelimitaboveisenforcedbythemediauploadendpoint.Inaddition,thereisaseparateproductentityspecificfilesizelimitwhichisappliedwhencallingtheTweetcreation(orsimilar)endpointswithmedia_id.Thefilesizelimitandotherconstraintsmayvarydependingonthemedia_categoryparameter. AnimatedGIFrecommendations AGIFmayfailduringTweetcreationevenifitiswithinthefilesizelimit.Adheretothefollowingconstraintstoimprovesuccessrates. Resolutionshouldbe<=1280x1080(widthxheight) Numberofframes<=350 Numberofpixels(width*height*num_frames)<=300million Filesize<=15Mb InordertoprocesslargerGIFs,usethechunkeduploadendpointwiththemedia_categoryparameter.ThisallowstheservertoprocesstheGIFfileasynchronously,whichisarequirementforprocessinglargerfiles.Passmedia_category=tweet_giftoenableasyncuploadbehaviorforTweetswithananimatedGIF.   Videospecificationsandrecommendations PleaseusetheAsyncPathformediauploads. Recommended: RecommendedVideoCodec:H264HighProfile RecommendedFrameRates:30FPS,60FPS RecommendedVideoResolution:1280x720(landscape),720x1280(portrait),720x720(square) RecommendedMinimumVideoBitrate:5,000kbps RecommendedMinimumAudioBitrate:128kbps RecommendedAudioCodec:AACLC RecommendedAspectRatio:16:9(landscapeorportrait),1:1(square) Advanced: Frameratemustbe60FPSorless Dimensionsmustbebetween32x32and1280x1024 Filesizemustnotexceed512mb Durationmustbebetween0.5secondsand140seconds Aspectratiomustbebetween1:3and3:1 Musthave1:1pixelaspectratio OnlyYUV4:2:0pixelformatissupported AudiomustbeAACwithLowComplexityprofile.High-EfficiencyAACisnotsupported Audiomustbemonoorstereo,not5.1orgreater MustnothaveopenGOP Mustuseprogressivescan   AdditionalInformation: Inthetablebeloweachrowrepresentsanuploadrecommendation,butisnotarequirement.Alluploadsareprocessedforoptimizationacrossmultipleplatforms. Orientation Width Height VideoBitrate AudioBitrate Landscape 1280 720 2048K 128K Landscape 640 360 768K 64K Landscape 320 180 256K 64K Portrait 720 1280 2048K 128K Portrait 360 640 768K 64K Portrait 180 320 256K 64K Square 720 720 2048K 128K Square 480 480 768K 64K Square 240 240 256K 32K Foranexampleofhowtouploadmedia,pleaseseethechunkedmediauploaddocumentation.   Troubleshooting ForissueswiththeMediaAPIs,browsethe MediaAPIcategoryinthedeveloperforumsforananswer. ByusingTwitter’sservicesyouagreetoourCookiesUse.Weusecookiesforpurposesincludinganalytics,personalisation,andads. OK ThispageandcertainotherTwittersitesplaceandreadthirdpartycookiesonyourbrowserthatareusedfornon-essentialpurposesincludingtargetingofads. Throughthesecookies,Google,LinkedInandDemandbasecollectpersonaldataaboutyoufortheirownpurposes. Learnmore. Accept Decline



請為這篇文章評分?