-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from a-legotin/develop
1.2.4
- Loading branch information
Showing
108 changed files
with
1,682 additions
and
532 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
language: csharp | ||
solution: InstaSharper.sln | ||
dotnet: 1.0.0-preview2-003121 | ||
sudo: required | ||
os: linux | ||
dist: trusty | ||
dotnet: 1.0.1 | ||
mono: none | ||
solution: InstaSharper.sln | ||
|
||
script: | ||
# dotnet info | ||
- cd InstaSharper | ||
- dotnet --info | ||
# Run dotnet new | ||
- dotnet restore | ||
- cd InstaSharper | ||
- dotnet build | ||
- cd ../InstaSharper.Tests | ||
- dotnet build | ||
- dotnet test -parallel none | ||
- dotnet build --framework netstandard1.6 |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using InstaSharper.API; | ||
using InstaSharper.API.Builder; | ||
using InstaSharper.Classes; | ||
using InstaSharper.Examples.Samples; | ||
|
||
namespace InstaSharper.Examples | ||
{ | ||
public class Program | ||
{ | ||
/// <summary> | ||
/// Api instance (one instance per Instagram user) | ||
/// </summary> | ||
private static IInstaApi _instaApi; | ||
|
||
private static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Starting demo of InstaSharper project"); | ||
// create user session data and provide login details | ||
var userSession = new UserSessionData | ||
{ | ||
UserName = "username", | ||
Password = "password" | ||
}; | ||
// create new InstaApi instance using Builder | ||
_instaApi = new InstaApiBuilder() | ||
.SetUser(userSession) | ||
.Build(); | ||
// login | ||
var logInResult = _instaApi.Login(); | ||
if (!logInResult.Succeeded) | ||
{ | ||
Console.WriteLine($"Unable to login: {logInResult.Info.Message}"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Press 1 to start basic demo samples"); | ||
Console.WriteLine("Press 2 to start upload photo demo sample"); | ||
Console.WriteLine("Press 3 to start comment media demo sample"); | ||
|
||
var key = Console.ReadKey(); | ||
switch (key.Key) | ||
{ | ||
case ConsoleKey.D1: | ||
new Basics(_instaApi).DoShow(); | ||
break; | ||
case ConsoleKey.D2: | ||
new UploadPhoto(_instaApi).DoShow(); | ||
break; | ||
case ConsoleKey.D3: | ||
new CommentMedia(_instaApi).DoShow(); | ||
break; | ||
default: | ||
break; | ||
} | ||
var logoutResult = _instaApi.Logout(); | ||
if (logoutResult.Value) Console.WriteLine("Logout succeed"); | ||
} | ||
Console.ReadKey(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Linq; | ||
using InstaSharper.API; | ||
using InstaSharper.Examples.Utils; | ||
|
||
namespace InstaSharper.Examples.Samples | ||
{ | ||
internal class Basics | ||
{ | ||
/// <summary> | ||
/// Config values | ||
/// </summary> | ||
private static readonly int _maxDescriptionLength = 20; | ||
|
||
private readonly IInstaApi _instaApi; | ||
|
||
public Basics(IInstaApi instaApi) | ||
{ | ||
_instaApi = instaApi; | ||
} | ||
|
||
public void DoShow() | ||
{ | ||
// get currently logged in user | ||
var currentUser = _instaApi.GetCurrentUser().Value; | ||
Console.WriteLine($"Logged in: username - {currentUser.UserName}, full name - {currentUser.FullName}"); | ||
|
||
// get self followers | ||
var followers = _instaApi.GetUserFollowersAsync(currentUser.UserName, 5).Result.Value; | ||
Console.WriteLine($"Count of followers [{currentUser.UserName}]:{followers.Count}"); | ||
|
||
// get self user's media, latest 5 pages | ||
var currentUserMedia = _instaApi.GetUserMedia(currentUser.UserName, 5); | ||
if (currentUserMedia.Succeeded) | ||
{ | ||
Console.WriteLine($"Media count [{currentUser.UserName}]: {currentUserMedia.Value.Count}"); | ||
foreach (var media in currentUserMedia.Value) | ||
ConsoleUtils.PrintMedia("Self media", media, _maxDescriptionLength); | ||
} | ||
|
||
//get user time line feed, latest 5 pages | ||
var userFeed = _instaApi.GetUserTimelineFeed(5); | ||
if (userFeed.Succeeded) | ||
{ | ||
Console.WriteLine( | ||
$"Feed items (in {userFeed.Value.Pages} pages) [{currentUser.UserName}]: {userFeed.Value.Medias.Count}"); | ||
foreach (var media in userFeed.Value.Medias) | ||
ConsoleUtils.PrintMedia("Feed media", media, _maxDescriptionLength); | ||
//like first 10 medias from user timeline feed | ||
foreach (var media in userFeed.Value.Medias.Take(10)) | ||
{ | ||
var likeResult = _instaApi.LikeMedia(media.InstaIdentifier); | ||
var resultString = likeResult.Value ? "liked" : "not liked"; | ||
Console.WriteLine($"Media {media.Code} {resultString}"); | ||
} | ||
} | ||
|
||
// get tag feed, latest 5 pages | ||
var tagFeed = _instaApi.GetTagFeed("quadcopter", 5); | ||
if (tagFeed.Succeeded) | ||
{ | ||
Console.WriteLine( | ||
$"Tag feed items (in {tagFeed.Value.Pages} pages) [{currentUser.UserName}]: {tagFeed.Value.Medias.Count}"); | ||
foreach (var media in tagFeed.Value.Medias) | ||
ConsoleUtils.PrintMedia("Tag feed", media, _maxDescriptionLength); | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using InstaSharper.API; | ||
|
||
namespace InstaSharper.Examples.Samples | ||
{ | ||
internal class CommentMedia | ||
{ | ||
private readonly IInstaApi _instaApi; | ||
|
||
public CommentMedia(IInstaApi instaApi) | ||
{ | ||
_instaApi = instaApi; | ||
} | ||
|
||
public void DoShow() | ||
{ | ||
var commentResult = _instaApi.CommentMedia("", "Hi there!"); | ||
Console.WriteLine(commentResult.Succeeded | ||
? $"Comment created: {commentResult.Value.Pk}, text: {commentResult.Value.Text}" | ||
: $"Unable to create comment: {commentResult.Info.Message}"); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.IO; | ||
using InstaSharper.API; | ||
using InstaSharper.Classes.Models; | ||
|
||
namespace InstaSharper.Examples.Samples | ||
{ | ||
internal class UploadPhoto | ||
{ | ||
private readonly IInstaApi _instaApi; | ||
|
||
public UploadPhoto(IInstaApi instaApi) | ||
{ | ||
_instaApi = instaApi; | ||
} | ||
|
||
public void DoShow() | ||
{ | ||
var mediaImage = new MediaImage | ||
{ | ||
Height = 1080, | ||
Width = 1080, | ||
URI = new Uri(Path.GetFullPath(@"c:\someawesomepicture.jpg"), UriKind.Absolute).LocalPath | ||
}; | ||
var result = _instaApi.UploadPhoto(mediaImage, "someawesomepicture"); | ||
Console.WriteLine(result.Succeeded | ||
? $"Media created: {result.Value.Pk}, {result.Value.Caption}" | ||
: $"Unable to upload photo: {result.Info.Message}"); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using InstaSharper.Classes.Models; | ||
|
||
namespace InstaSharper.Examples.Utils | ||
{ | ||
public static class ConsoleUtils | ||
{ | ||
public static void PrintMedia(string header, InstaMedia media, int maxDescriptionLength) | ||
{ | ||
Console.WriteLine( | ||
$"{header} [{media.User.UserName}]: {media.Caption?.Text.Truncate(maxDescriptionLength)}, {media.Code}, likes: {media.LikesCount}, multipost: {media.IsMultiPost}"); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace InstaSharper.Examples.Utils | ||
{ | ||
public static class StringExtensions | ||
{ | ||
public static string Truncate(this string value, int maxChars) | ||
{ | ||
return value.Length <= maxChars ? value : value.Substring(0, maxChars) + "..."; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.