Last active
August 12, 2022 12:29
-
-
Save dmitriy-chernysh/8bfb4ebb9f2999c60649736b71d21b8e 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
VideoUploader.uploadAsyncWithProgressCallback( | |
videoContentBuilder.build(), | |
pageId, | |
object : GraphRequest.OnProgressCallback { | |
override fun onCompleted(response: GraphResponse) { | |
// {Response: responseCode: 200, graphObject: {"success":true,"video_id":"380208427529152"} | |
try { | |
val videoId = parseResponseVideoId(response.jsonObject) | |
if (videoId.isNullOrEmpty()) | |
onFail("Failed to share video to Facebook: $response") | |
else | |
onSuccess(getPostUrl(userOrPageId, videoId)) | |
} catch (e: Exception) { | |
onFail("Failed to share video to Facebook: ${e.localizedMessage}") | |
} | |
} | |
override fun onProgress(current: Long, max: Long) { | |
if (currentTime - lastTimeProgressUpdated > 1000) { | |
val progress: Float = | |
if (max > 0) (current * 100 / max.toFloat()) else 0F | |
onProgress(progress) | |
} | |
} | |
} | |
) |
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
@Throws(JSONException::class) | |
private fun parseResponseVideoId(json: JSONObject?): String? = | |
json?.getString(KEY_VIDEO_ID) | |
private fun getPostUrl(userOrPageId: String, postId: String): String = | |
"fb.com/$userOrPageId/$postId/" | |
private const val KEY_VIDEO_ID = "video_id" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment