Created
January 10, 2014 21:12
-
-
Save kcleereman/8362706 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val youTubeService: YouTubeService = { | |
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets | |
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport | |
import com.google.api.client.json.jackson2.JacksonFactory | |
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential | |
import com.google.api.client.googleapis.auth.oauth2.GoogleOAuthConstants | |
val devKey = "" | |
val service = new YouTubeService("Blank", devKey) | |
val transport = GoogleNetHttpTransport.newTrustedTransport() | |
val jsonFactory = JacksonFactory.getDefaultInstance | |
val accessToken = "" | |
val refreshToken = "" | |
val clientId = "" | |
val clientSecret = "" | |
val redirectUris = { | |
val temp = new java.util.ArrayList[String] | |
temp.add("") | |
temp | |
} | |
val clientSecrets: GoogleClientSecrets = { | |
val secrets = new GoogleClientSecrets() | |
val details = new GoogleClientSecrets.Details() | |
details.setAuthUri(GoogleOAuthConstants.AUTHORIZATION_SERVER_URL) | |
details.setClientId(clientId) | |
details.setClientSecret(clientSecret) | |
details.setRedirectUris(redirectUris) | |
details.setTokenUri(GoogleOAuthConstants.TOKEN_SERVER_URL) | |
secrets.setWeb(details) | |
secrets | |
} | |
val googleCredential: GoogleCredential = new GoogleCredential.Builder() | |
.setTransport(transport) | |
.setJsonFactory(jsonFactory) | |
.setClientSecrets(clientSecrets) | |
.build() | |
.setAccessToken(accessToken) | |
.setRefreshToken(refreshToken) | |
googleCredential.refreshToken() | |
service.setOAuth2Credentials(googleCredential) | |
service | |
} | |
private val uploadUrl = new URL("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads") | |
def uploadVideo(user: User, file: File): SResult[String] = { | |
val videoEntry = new VideoEntry | |
val mediaGroup = videoEntry.getOrCreateMediaGroup | |
mediaGroup.setTitle(new MediaTitle()) | |
mediaGroup.getTitle.setPlainTextContent("Test Title") | |
mediaGroup.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Sports")) | |
mediaGroup.setKeywords(new MediaKeywords) | |
mediaGroup.getKeywords.addKeyword("sports") | |
mediaGroup.setDescription(new MediaDescription) | |
mediaGroup.getDescription.setPlainTextContent("Description") | |
mediaGroup.setPrivate(false) | |
mediaGroup.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "dev tag")) | |
videoEntry.setLocation("New York, NY") | |
videoEntry.setMediaSource(new MediaFileSource(file, "video/mp4")) | |
// val videoFeed = youTubeService.getFeed(new URL("http://gdata.youtube.com/feeds/api/standardfeeds/most_popular"), classOf[VideoFeed]) | |
// println | |
// println(videoFeed.getEntries.get(0).getId) | |
// println | |
val createdEntry = youTubeService.insert(uploadUrl, videoEntry) | |
createdEntry.getId.sSuccess | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment