Features
- Drag and drop image from any where.
- Auto attach URL of your blog to your tweet image.
API Download :
Before Creating your C# app you must know to create new app in Twitter Dev. the following link Contains only API Download and its documentation Click Here
Source Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Tweetinvi;
using Tweetinvi.Core.Interfaces;
using Tweetinvi.Core.Interfaces.Controllers;
using Tweetinvi.Core.Interfaces.DTO;
using Tweetinvi.Core.Interfaces.Factories;
using Tweetinvi.Core.Interfaces.Models;
namespace TwitterApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected bool validData;
string path;
protected Image image;
protected Thread getImageThread;
string AccessToken="Your_Access_token";
string TokenSecret = "Your_Token_Secret";
string ConsumerKey = "Your_Consumer_key";
string ConsumerSecret ="Your_Consumer_Secret";
private void Form1_Load(object sender, EventArgs e)
{
Tweetinvi.TwitterCredentials.SetCredentials(AccessToken,TokenSecret,ConsumerKey,ConsumerSecret);
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (validData)
{
while (getImageThread.IsAlive)
{
Application.DoEvents();
Thread.Sleep(0);
}
pictureBox1.Image = image;
}
}
protected void LoadImage()
{
image = new Bitmap(path);
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
string filename;
validData = GetFilename(out filename, e);
if (validData)
{
path = filename;
getImageThread = new Thread(new ThreadStart(LoadImage));
getImageThread.Start();
e.Effect = DragDropEffects.Copy;
}
else
e.Effect = DragDropEffects.None;
}
private bool GetFilename(out string filename, DragEventArgs e)
{
bool ret = false;
filename = String.Empty;
if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
{
Array data = ((IDataObject)e.Data).GetData("FileDrop") as Array;
if (data != null)
{
if ((data.Length == 1) && (data.GetValue(0) is String))
{
filename = ((string[])data)[0];
string ext = Path.GetExtension(filename).ToLower();
if ((ext == ".jpg") || (ext == ".png") || (ext == ".bmp"))
{
ret = true;
}
}
}
}
return ret;
}
private void TweetBtn_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true && checkBox2.Checked==true)
{
string BlogUrl = "Click www.ziabse.blogspot.com For More...";
byte[] file = File.ReadAllBytes(path);
var tweet = Tweet.PublishTweetWithMedia(BlogUrl,file);
var imageURL = tweet.Entities.Medias.First().MediaType;
label1.Text = "Tweet Posted With Image :)";
}
else
if (textBox1.Text != "")
{
Tweet.PublishTweet(textBox1.Text);
label1.Text = " Tweet Posted :)";
}
else
label1.Text = "Tweet Can't Be Blank :D";
}
}
}
No comments:
Post a Comment