How to upload video on twitpic/twitter programatically? [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am new in Android.
I was working for uploading Image/Video on Twitter. I used the twitpic for this purpose.
I first sent image to twitpic and then updated the status in twitter with url of the tweet.
Image is successfully loading as per my selection from gallery.
But I am stuck in uploading video on Twitter. As there is option of twitpic or twitvid for uploading video. But there is no such type of code or sdk given. So confused that how to do this, which classes has to be used.
I need a sample code for uploading video.

Was stuck on this for a while myself as well (not a lot of examples around) and found a non-working example here on SO which I've managed to hammer into shape...
First you'll need the twitvid Java API
1 download the jar file (I used twitvid-java 1.6.1)
2 put it in your "libs" folder
3 right-click on your project and go to "properties"
4 select "Java build path" and include the jar ("libraries" tab) and make sure it's built ("order and export" tab)
The code that follows assumes you've already made a token with the regular twitter4j methods:
private void postToTwitvid(String videoPath){
AccessToken token = mTwitter.getAccessToken();
Values values = new Values();
values.setSession(new Session());
TwitvidApi api = new TwitvidApi(values);
api.setSecureUrlEnabled(false);
Session session;
try {
session = api.authenticate(new TwitterAuthPack.Builder()
.setConsumerKey(twitter_consumer_key)
.setConsumerSecret(twitter_secret_key)
.setOAuthToken(token.getToken())
.setOAuthTokenSecret(token.getTokenSecret())
.build());
api.getValues().setSession(session);
final UploadHelper helper = new UploadHelper(api);
File file=new File(videoPath);
TwitvidPost twitvidPost = new TwitvidPost.Builder()
.setFile(file).setChunkSize(10485760)
.setMessage("Twitvid test")
.setPostToTwitter(true)
.create();
try {
if (helper.upload(twitvidPost))
{
Toast.makeText(TwitterShare.this, "Posted on Twitter and Twitvid", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(TwitterShare.this, "Post failed", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (ApiException e1) {
e1.printStackTrace();
}
}
The token depends on how you've implemented the regular posting to twitter, just include yours.
Hope this helps!
PS: I had to force the UI thread to accept network connections to make this work
(My first answer! w00t!)

Related

How to prevent url to show in web view [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Hi there I am trying to create app where I am using web view to show my google drive folder but whenever internet got disconnect in between loading the URL at that a msg comes with showing the URL information.
What can I do to prevent showing URL from users.
Is it possible to show some other msg whenever internet goes down on starting or when it goes down on after starting loading.
I have a custom HTML page that will show if something wrong happened when loading the url.
webView.setWebViewClient(new WebViewClient(){
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
switch(errorCode){
case ERROR_HOST_LOOKUP:
webView.loadDataWithBaseURL(null,"<YOUR OWN CUSTOM HTML PAGE TO SHOW WHEN THERE'S AN ERROR>", "text/html", "UTF-8",null);
break;
case ERROR_CONNECT:
webView.loadDataWithBaseURL(null,"<YOUR OWN CUSTOM HTML PAGE TO SHOW WHEN THERE'S AN ERROR>", "text/html", "UTF-8",null);
break;
case ...[IF YOU WANT TO CATCH MORE ERRORS]
}
}
}
Reference: https://developer.android.com/reference/android/webkit/WebViewClient#onReceivedError(android.webkit.WebView,%20int,%20java.lang.String,%20java.lang.String)
Error Code Reference:
https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_AUTHENTICATION
Yes! You can either print the message or redirect the user to some other activity by checking the following method soon after the app gets launches...
DD4YouConfig dd4YouConfig = new DD4YouConfig(context);
if (dd4YouConfig.isInternetConnectivity()) {
//redirect to webview
}
else
{
//call alert dialog stating no internet
}
This is a library function so obviously don't fail to add this line in Gradle
implementation 'in.dd4you.appsconfig:appsconfig:1.3.3'

Google Drive REST Api download file by its fileId

Hello guys I run into a problem. In my application I am storing fileId's of files which user selected before in GoogleDrive file picker. Also I am storing a local copy of that files in device. After each start I want to refresh local files, so I want to download them from drive. But it is not cleare for me, how should i do this.
I saw this documentation, but I can't understand where to get driveService, which used in this code
driveService.files().get(fileId)
.executeMediaAndDownloadTo(outputStream);
I don't know what driveService is in this code. (Which class instance) and how do I get it
Help me please, thank you.
P.S.
Sorry for my bad english
you should check the documentation under resumable Media Downloads it might give you some clues.
class CustomProgressListener implements MediaHttpDownloaderProgressListener {
public void progressChanged(MediaHttpDownloader downloader) {
switch (downloader.getDownloadState()) {
case MEDIA_IN_PROGRESS:
System.out.println(downloader.getProgress());
break;
case MEDIA_COMPLETE:
System.out.println("Download is complete!");
}
}
}
OutputStream out = new FileOutputStream("/tmp/driveFile.jpg");
DriveFiles.Get request = drive.files().get(fileId);
request.getMediaHttpDownloader().setProgressListener(new CustomProgressListener());
request.executeMediaAndDownloadTo(out);
BaseClientService service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Drive API Sample",
});
You should check this stack answer, maybe it will help you understand it:
How do you create a new Google Drive Service in C# using OAuth

Download youtube videos with Java API?

I found similar questions in Stack Overflow, and I tried few of solutions. All are outdated, so I am raising a new issue.
I followed and tried:
How to download videos from youtube on java?
I gone through the youtube-api, it not providing anything to download as I understand the samples provided in Github.
https://developers.google.com/youtube/v3/code_samples/java
It tried with latest VGet API, it working well but it downloading video(mp4) and audio (webm) separately. How can I combine both?
import com.github.axet.vget.VGet;
public class YoutubeDownloadTool {
public static void main(String[] args) {
try {
String url = "https://www.youtube.com/watch?v=7lFhwXeSidQ";
String path = "D:\\videos";
VGet v = new VGet(new URL(url), new File(path));
v.download();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Downloading of videos is not supported in Youtube API. It is in fact prohibited. Under Terms of Service - II. Prohibitions it is mentioned that:
Prohibited
store copies of YouTube audiovisual content
use the YouTube API intentionally to encourage or promote copyright infringement or the exploitation of copyright-infringing materials;
Also, this SO thread states that is explicitly mentioned in Youtube Page terms
"You shall not download any Content unless you see a “download” or similar link displayed by YouTube on the Service for that Content. You shall not copy, reproduce, distribute, transmit, broadcast, display, sell, license, or otherwise exploit any Content for any other purposes without the prior written consent of YouTube or the respective licensors of the Content "

How to start an OpenOffice extension? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to write an extension for OpenOffice.
This extension would be written in java (compiled, I don't want people to see the code).
It should do actions when I start openOffice writer, when I click on a button and when I print.
I've already added the button but I can't find how to link it with the code of what it should do.
I've read the wiki and the DevGuide but I don't find it very clear.
Could you please help me to start understanding how to create an extension (where should I put my code, how to link it with the GUI etc...)?
As an example, follow instructions at https://wiki.openoffice.org/wiki/OpenOffice_NetBeans_Integration#Configuration. Install the Apache OpenOffice API Plugin by going to Tools -> Plugins.
Click on the link that says OpenOffice.org Add-On Project Type to get more instructions. If you haven't yet, download AOO 4.1.2 and the AOO 4.1.2 SDK. (The plugin did not work for me using LibreOffice, but the resulting extension did work in LibreOffice).
After the code is generated according to the instructions, then add this code to the dispatch method of TestAddOn.java:
if ( aURL.Path.compareTo("HelloWorld") == 0 )
{
// add your own code here
com.sun.star.frame.XController xController = m_xFrame.getController();
if (xController != null) {
XModel xModel = (com.sun.star.frame.XModel) xController.getModel();
XTextDocument xTextDocument = (com.sun.star.text.XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, xModel);
XText xText = xTextDocument.getText();
XTextRange xTextRange = xText.getEnd();
xTextRange.setString( "Hello World (in Java)" );
return;
}
}
Now compile and deploy the extension. When the "Hello World" toolbar button is clicked, it should put "Hello World (in Java)" in the document.
The code was adapted from https://forum.openoffice.org/en/forum/viewtopic.php?f=47&t=72459.
In order to handle events like when the document is opened, I also tried calling a method of the extension from Basic code like this:
Sub CallJavaMacro
MSPF = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
scriptPro = MSPF.createScriptProvider("")
xScript = scriptPro.getScript("vnd.sun.star.script:" & _
"com.example.testaddon.TestAddOn.PutHello?" & _
"language=Java&location=user:uno_packages/TestAddOn.oxt")
Thing = xScript.Invoke()
End Sub
However the Basic routine said it could not find the method. Maybe I did not declare the method properly or something.

NFC Mifare Ultralight tags writing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Any tutorial for how to write on Mifare Ultralight tags ?
I have been searching for a while
MifareUltraLight tags it contains 16 page and each page contains 4 bytes. Its first 4 page contains manufacturer info , OTP and locking bytes.
After getting The Tag you can get MifareUltralight class using this:
MifareUltralight mifare = MifareUltralight.get(tag);
When you get the tag then before read and write into a page you must have to connect. When Connect successfully then using this Command you can write:
mifare.writePage(pageNumber, pageData.getBytes("US-ASCII"));
here pageNumber is the page where you want to write and page data is Data that you want to write. pageData must be equals 4 bytes and page Number must less than 16.
The Complete Code is here:
public void writeOnMifareUltralightC( Tag tag,
String pageData, int pageNumber) {
MifareUltralight mifare = null;
try {
mifare = MifareUltralight.get(tag);
mifare.connect();
mifare.writePage(pageNumber, pageData.getBytes("US-ASCII"));
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
mifare.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
You can also see the code sample From my repository
You might want to look at this StackOverflow question:
Writing NFC tags using a Nexus S
Also, if you haven't done so already, read through the NFC Basics document on the Android developers' site:
http://developer.android.com/guide/topics/nfc/nfc.html
(Admittedly, there's not much documentation out there on this yet. If you get this working, I'd encourage you to write a technical blog post on your experiences!)

Categories