/
New_LikePosts.aspx.cs
114 lines (89 loc) · 3.23 KB
/
New_LikePosts.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using AutoPost.Database;
using InstagramApiSharp.API;
using InstagramApiSharp.API.Builder;
using InstagramApiSharp.Classes;
using InstagramApiSharp.Classes.Android.DeviceInfo;
using InstagramApiSharp.Classes.Models;
using InstagramApiSharp.Classes.SessionHandlers;
using InstagramApiSharp.Enums;
using InstagramApiSharp.Logger;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
namespace AutoPost
{
public partial class New_LikePosts : System.Web.UI.Page
{
private static IInstaApi ınstagramApi;
const string StateFile = "state.bin";
DbClassSQL db = new DbClassSQL();
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
return;
}
if (Session["username"] == null)
{
Response.Redirect("New_Login1.aspx");
}
}
protected void LikeButton_Click1(object sender, EventArgs e)
{
string url = UrlText.Text;
long id = shortcodeToInstaID(url);
string Id = id.ToString();
LikeButton.Text = Id;
DataTable dt = new DataTable();
dt = db.Fill("select * from Userstbl ");
for (int i = 0; i < dt.Rows.Count; i++)
{
var userSession = new UserSessionData
{
UserName = dt.Rows[i]["Username"].ToString(),
Password = dt.Rows[i]["Password"].ToString()
};
var delay = RequestDelay.FromSeconds(2, 2);
ınstagramApi = InstaApiBuilder.CreateBuilder()
.SetUser(userSession)
.UseLogger(new DebugLogger(LogLevel.Exceptions)) // use logger for requests and debug messages
.SetRequestDelay(delay)
//.SetDevice(androidDevice);
.SetSessionHandler(new FileSessionHandler() { FilePath = StateFile })
.Build();
var r = Task.Run(() => ınstagramApi.LoginAsync());
if (r.Result.Succeeded)
{
LikeButton.Text = "Login";
}
// var z = Task.Run(() => ınstagramApi.MediaProcessor.GetMediaIdFromUrlAsync(uri));
// string ID = z.Result.Value;
//string id = "2372503629901614370";
var x = Task.Run(() => ınstagramApi.MediaProcessor.LikeMediaAsync(Id));
//if (x.Result.Succeeded)
//{
// LikeButton.Text = "Liked Successfully";
//}
}
//LoadSession();
}
void LoadSession()
{
ınstagramApi?.SessionHandler?.Load();
}
public long shortcodeToInstaID(string Shortcode)
{
var chr = ' ';
long id = 0;
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
for (var i = 0; i < Shortcode.Length; i++)
{
chr = Shortcode[i];
id = (id * 64) + alphabet.IndexOf(chr);
}
return id;
}
}
}