Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Isse Kun
Emektar Üye
Katılım
15 May 2017
Mesajlar
4,801
Çözümler
5
Tepki puanı
2,106
Ödüller
15
Sosyal
9 HİZMET YILI
Merhaba arkadaşlar, bugün Pastebin'de Yapıştırmak için bazı sınıfları yazmayı bitirdim. İşimi kolaylaştırmak için API'yi kullandım.

VB.Net:
Imports System.Collections.Specialized
Imports System.Net
Imports System.Text

Public Class Paste

    Dim _devkey As String
    Dim _username As String
    Dim _userpassword As String
    Dim _PasteCode As String
    Dim _PasteName As String
    Dim _Syntax As String
    Dim _ExpireDate As String
    Dim _PasteExposure As Integer
    Dim ukey As String
    Sub New(ByVal Key As String, ByVal username As String, ByVal password As String, ByVal PasteCode As String, _
            ByVal PasteName As String, ByVal PasteExposure As Integer, ByVal SyntaxHighlighting As String, _
            ByVal ExpireDate As String)
        _devkey = Key
        _username = username
        _userpassword = password
        _PasteCode = PasteCode
        _PasteName = PasteName
        _PasteExposure = PasteExposure
        _Syntax = SyntaxHighlighting
        _ExpireDate = ExpireDate
    End Sub

    Public Function Start() As String
        Dim chiavi As New NameValueCollection()
        chiavi.Add("api_dev_key", _devkey)
        chiavi.Add("api_user_name", _username)
        chiavi.Add("api_user_password", _userpassword)

        Dim wClient As New WebClient()
        Dim risposta As String = Encoding.UTF8.GetString(wClient.UploadValues("https://pastebin.com/api/api_login.php", chiavi))

        If risposta.ToLower.Contains("bad api request") Then
            MessageBox.Show("Login failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return "ERROR"
        Else
            ukey = risposta
            Try
                Dim output As String = MakePaste() 'Restituisce una stringa
                Process.Start(output)
                Return "SUCCESS"
            Catch Ex As Exception
                MessageBox.Show("Exception: " & Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Return "ERROR"
            End Try
        End If
    End Function

    Public Function MakePaste() As String
        If ukey = "" Then Return "ERROR"

        Dim chiavi As New NameValueCollection()
        chiavi.Add("api_dev_key", _devkey)
        chiavi.Add("api_user_key", ukey)
        chiavi.Add("api_option", "paste")
        chiavi.Add("api_paste_code", _PasteCode)
        chiavi.Add("api_paste_name", _PasteName)
        chiavi.Add("api_paste_format", _Syntax)
        chiavi.Add("api_paste_private", _PasteExposure)
        chiavi.Add("api_paste_expire_date", "N")

        Dim wc As New WebClient()
        Dim Risultato As String = ""
        Dim Risposta As String = Encoding.UTF8.GetString(wc.UploadValues( _
                                                         "https://pastebin.com/api/api_post.php", chiavi))

        If Risposta.ToLower.Contains("bad api request") Then
            ' Key non valida
        Else
            Risultato = Risposta
        End If
        Return Risultato
    End Function
End Class

C#:
using System.Collections.Specialized;
using System.Net;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System;

public class Paste
{

    private string _devkey;
    private string _username;
    private string _userpassword;
    private string _PasteCode;
    private string _PasteName;
    private string _Syntax;
    private string _ExpireDate;
    private int _PasteExposure;
    private string ukey;
    public Paste(string Key, string username, string password, string PasteCode, string PasteName, int PasteExposure, string SyntaxHighlighting, string ExpireDate)
    {
        _devkey = Key;
        _username = username;
        _userpassword = password;
        _PasteCode = PasteCode;
        _PasteName = PasteName;
        _PasteExposure = PasteExposure;
        _Syntax = SyntaxHighlighting;
        _ExpireDate = ExpireDate;
    }

    public string Start()
    {
        NameValueCollection chiavi = new NameValueCollection();
        chiavi.Add("api_dev_key", _devkey);
        chiavi.Add("api_user_name", _username);
        chiavi.Add("api_user_password", _userpassword);

        WebClient wClient = new WebClient();
        string risposta = Encoding.UTF8.GetString(wClient.UploadValues("https://pastebin.com/api/api_login.php", chiavi));

        if (risposta.ToLower().Contains("bad api request"))
        {
            MessageBox.Show("Login failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return "ERROR";
        }
        else
        {
            ukey = risposta;
            try
            {
                string output = MakePaste();
                Process.Start(output);
                return "SUCCESS";
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Exception: " + Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return "ERROR";
            }
        }
    }

    public string MakePaste()
    {
        if (ukey == "")
        {
            return "ERROR";
        }

        NameValueCollection chiavi = new NameValueCollection();
        chiavi.Add("api_dev_key", _devkey);
        chiavi.Add("api_user_key", ukey);
        chiavi.Add("api_option", "paste");
        chiavi.Add("api_paste_code", _PasteCode);
        chiavi.Add("api_paste_name", _PasteName);
        chiavi.Add("api_paste_format", _Syntax);
        chiavi.Add("api_paste_private", _PasteExposure.ToString());
        chiavi.Add("api_paste_expire_date", "N");

        WebClient wc = new WebClient();
        string Risultato = "";
        string Risposta = Encoding.UTF8.GetString(wc.UploadValues("https://pastebin.com/api/api_post.php", chiavi));

        if (Risposta.ToLower().Contains("bad api request"))
        {
            
        }
        else
        {
            Risultato = Risposta;
        }

        return Risultato;
    }
}

Şimdi sınıfın bir örneğini oluşturalım "Yapıştır" düğmesine basalım.

VB.Net:
Dim Maker As New Paste("your pastebin API", "your pastebin username", "your pastebin password", txtCode.Text, _
                               "paste name", 1, "php", "N")
        ' Parameter ExpireDate> N= Never // 1M= 1 Month // 10M= 10 Minutes e così via, etc...
        ' Parameter PasteExposure> 0= Public // 1= Unlisted // 2= Private
        Maker.Start()

C#:
Paste np = new Paste("your pastebin API key", "your pastebin username", "your pastebin password", txtCode.Text, "paste name", 2, "php", "N");
            np.Start();

Konumu okuduğunuz için teşekkür ederim umarım bir işinize yarar.
 
Onaylı Üye
Katılım
14 Tem 2016
Mesajlar
102
Tepki puanı
8
Ödüller
9
Yaş
23
9 HİZMET YILI
Hacim Kendin mi Kodluyorsun Yoksa Yardım Mı alıyorsun
 
Banlı Üye
Katılım
11 Tem 2017
Mesajlar
1,777
Çözümler
2
Tepki puanı
695
8 HİZMET YILI
Şu Paste Binden Ne Kadar Nefret Etsem Az Keşke Paste Bin Kodlamasaydın ama gene neyse Elerine sağlık güzel yapmışsın
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst