Search Unity

[RELEASED] Instagram API (Object oriented, event based...)

Discussion in 'Assets and Asset Store' started by bdovaz, Jan 2, 2016.

  1. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    If you read documentation (my asset and official Instagram docs) you will see it:

    public void Auth(string redirect, string[] scope);

    Scope array is what you want.
     
  2. neurograph

    neurograph

    Joined:
    Jun 8, 2010
    Posts:
    24
    Hi I'm getting this error since I updated the project to Unity 2017 can you please help me?

    NullReferenceException: Object reference not set to an instance of an object
    Instagram.InstagramAPI.HandleComplete (System.String json, System.Action`1 OnComplete) (at Assets/InstagramAPI/Source/API/InstagramAPI.cs:499)
    Instagram.InstagramAPI+<DoGet>c__AnonStorey3.<>m__1 (System.String json) (at Assets/InstagramAPI/Source/API/InstagramAPI.cs:358)
    Instagram.UWebRequest+<DoGet>c__Iterator0.MoveNext () (at Assets/InstagramAPI/Source/Request/UWebRequest.cs:51)
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
     
  3. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    I'm checking it but line numbers don't match with the current version, I don't understand it.

    Can you send me a minimal repro project? It's the best thing you can do.

    I need to know what are you trying to do exactly to know what it's happening.

    Are you settings this flags to true so you can log more information?

    endpointLogEnabled
    jsonLogEnabled

    It's really weird that updating Unity version breaks "UnityWebRequest" calls.
     
  4. incorp-sergio

    incorp-sergio

    Joined:
    Nov 15, 2017
    Posts:
    3
    Hi! Just try to make any simple request - authorize and get some data. Compiling on my android device.
    Error:
    "AndroidJavaException: android.content.ActivityNotFoundException:
    Unable to find explicit activity class
    {com.unity.sampleassets/com.bdovaz.instaplugin.WebViewActivity};
    have you declared this activity in your AndroidManifest.xml?"

    My AndroidManifest.xml:"
    <?xml version="1.0" encoding="utf-8"?>
    <manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.unity3d.player"
    xmlns:tools="http://schemas.android.com/tools"
    android:installLocation="preferExternal"
    android:versionCode="1"
    android:versionName="1.0">
    <supports-screens
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"
    android:xlargeScreens="true"
    android:anyDensity="true"/>

    <application
    android:theme="@StyLe/UnityThemeSelector"
    android:icon="@drawable/app_icon"
    android:label="@String/app_name">
    <activity android:name="com.unity3d.player.UnityPlayerActivity"
    android:label="@String/app_name">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
    <activity android:name="com.bdovaz.instaplugin.WebViewActivity" android:label="@String/app_name" />
    </application>
    </manifest>"

    My code:
    "void Start()
    {
    Debug.Log("Start");

    authButton.onClick.AddListener(() => {
    InstagramAPI.Instance.Auth(Redirect, scope);
    });

    InstagramAPI.Instance.OnLogin += (sender) =>
    {
    InstagramAPI.Instance.LogInfo("On Login");
    authButton.interactable = false;
    };

    InstagramAPI.Instance.OnLoginCanceled += (sender) =>
    {
    InstagramAPI.Instance.LogInfo("Login cancel");
    authButton.interactable = true;
    };
    }"

    Can you help with it?
     
  5. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    Do you have your AndroidManifest.xml in Assets/Plugins/Android/AndroidManifest.xml?

    Have you tried a blank project and publishing the example scene?

    It should work out of the box.

    Check if it's something wrong on your end.
     
  6. incorp-sergio

    incorp-sergio

    Joined:
    Nov 15, 2017
    Posts:
    3
    It should work out of the box, but it obviously doesn't :)

    Try to publishing the example scene:
    <i>AndroidPlayer(ADB@127.0.0.1:34999)</i> AndroidJavaException: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.midcoregame.CelebrityApp/com.bdovaz.instaplugin.WebViewActivity}; have you declared this activity in your AndroidManifest.xml?
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.midcoregame.CelebrityApp/com.bdovaz.instaplugin.WebViewActivity}; have you declared this activity in your AndroidManifest.xml?
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1815)

    And yes, I have AndroidManifest.xml in Assets/Plugins/Android/AndroidManifest.xml and even paste the full text of it in my previous message.

    Any ideas?
     
  7. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    What exactly Unity version are you trying with?

    It's weird that in almost two years is the first error of this kind. I will check it with that version if it's a bug on Unity because I don't understand.
     
  8. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    I have tried the following:

    - Unity 2017.2.0 (latest one).
    - New project.
    - Import asset.
    - Publish to Android.

    It worked well.

    I don't understand what it's happening to you.
     
  9. incorp-sergio

    incorp-sergio

    Joined:
    Nov 15, 2017
    Posts:
    3
    I do the same things. Maybe its because I coding on Mac.
     
  10. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    Try to publish from Windows if you can and also to decompile your apk and see if the activity it's declared on AndroidManifest file because it seems that it's the source of your problem.
     
  11. KrlinM

    KrlinM

    Joined:
    Oct 23, 2013
    Posts:
    12
    Good day, Im thinking about buying this plugin. However I have no experience with instagram API and things like that. Is it possible to get number of all likes which user received on all his posts? (Sum of all received likes on his photos and videos?). If is it possible, how I can do it with this plugin?
     
  12. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    With my current API it's possible BUT I don't know what happens if that user has a huge amount of media items posted because it could be possible that Instagram doesn't allow to make many request per second.

    With this method it makes N requests paginated (because Instagram API makes it this way) until it reaches the "last page":

    public delegate void UserMediaRecentHandler(InstagramAPI sender, Media[] media);
    public event UserMediaRecentHandler OnUserMediaRecentRetrieved;

    public void GetUserRecentMedia();

    Each "Media" instance has a "LikesCount" property where you could do:

    int allLikesCount = media.Sum(e => e.LikesCount);
     
  13. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    With my current API it's possible BUT I don't know what happens if that user has a huge amount of media items posted because it could be possible that Instagram doesn't allow to make many request per second.

    Edit: here you have the allowed limits: https://www.instagram.com/developer/limits/

    As you can read you can make requests 5000 per hour per token (= user).

    With this method it makes N requests paginated (because Instagram API makes it this way) until it reaches the "last page":

    public delegate void UserMediaRecentHandler(InstagramAPI sender, Media[] media);
    public event UserMediaRecentHandler OnUserMediaRecentRetrieved;

    public void GetUserRecentMedia();

    Each "Media" instance has a "LikesCount" property where you could do:

    int allLikesCount = media.Sum(e => e.LikesCount);
     
  14. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    Due to the recent scandal, Facebook (Instagram's owner) it's making many changes on the old Instagram API (the current that it's using this asset) deprecating many endpoints (some of them earlier than they said) and forcing to use the new Instagram Graph API that it's business oriented.

    The current working endpoints that will work until December 11, 2018 are this (open each to see them more in detail section): https://www.instagram.com/developer/endpoints/

    GET /users/self -> Get information about the owner of the access token.
    GET /users/self/media/recent -> Get the most recent media of the user.
    GET /media/search -> Search for recent media in a given area.
    GET /media/media-id/comments -> Get a list of recent comments on a media object.
    GET /tags/tag-name -> Get information about a tag object.
    GET /tags/tag-name/media/recent -> Get a list of recently tagged media.
    GET /tags/search -> Search for tags by name.
    GET /locations/location-id-> Get information about a location.
    GET /locations/location-id/media/recent-> Get a list of media objects from a given location.
    GET /locations/search-> Search for a location by geographic coordinate.

    The other ones are not going to work (the ones that claimed to be removed on July 31, 2018), I haven't tested it yet but according to that info that it's the expected result.

    I'm working on rewriting the entire code for Instagram Graph API that it's entirely different:

    https://developers.facebook.com/docs/instagram-api

    It's a really bad situation where is putting us (developers) because that decision on prematurely deprecating some endpoints was mentioned on April 4 and also there are also some new endpoints on Graph API that are only for closed beta testing and are not available to everyone so I'm rewriting all the API but I can't rewrite it faster than I'm able to.

    That API it's currently 100% focused on business profiles but they said that in early 2019 it will have non business capabilities. Seen that the endpoints mentioned above are going to be deprecated on December and that it will be opened to non business profiles on early 2019 I expect to be an easier transition.

    That business account conversion it's free of course but you only can interact with your business profile data, you can't get any random user data.

    More info on the changes:

    https://techcrunch.com/2018/04/04/facebook-instagram-api-shut-down/
    https://developers.facebook.com/blog/post/2018/01/30/instagram-graph-api-updates/
    https://www.instagram.com/developer/
    https://www.instagram.com/developer/changelog/
     
    siddharth3322 likes this.
  15. tech_jasonbruges

    tech_jasonbruges

    Joined:
    Jul 18, 2017
    Posts:
    1
    Thank you very much for being clear and informative on this matter. Can you give any information about the release date of your rewritten API?
     
  16. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    The problem I'm having is that as I previously said, some endpoints are in a closed beta testing only for selected users so I can't test some endpoints for now...

    I'm thinking on working only on public endpoints and skip for now that closed beta endpoints so I'm not blocked.

    I wrote that post so you can know that I'm actively working on the new API but I will be conservative for now because they are making changes and I need to be sure that it's stable enough.

    I can't give a specific date on this because it's so much work to rewrite and test all the new API. All I can say is that it will be before the old API is removed.

    Anyway I will regularly keep you posted on this thread.
     
  17. skoteskote

    skoteskote

    Joined:
    Feb 15, 2017
    Posts:
    87
    @N3uRo Hi, and thanks for what looks like an awesome plugin! Just a double check before I buy it:

    Does this plugin allow me to download the 100 (or any number) latest public posts with a certain hashtag? I will use these images as textures in my game, how do they get stored? So that for example the user can type in #unity3d and display the 100 latests posts with that hashtag in the game.

    Thanks!
     
  18. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    It seems like it should be possible using the following method:

    public void GetTagRecentMedia(string name, int count);
     
  19. Drezus

    Drezus

    Joined:
    Oct 14, 2013
    Posts:
    13
    Does it support callbacks? (ex: Am I able to check if a user completed a sharing process fully or aborted it halfway?)
     
  20. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    All endpoints use UnityWebRequest so you should be able to cancel them tweaking the code a bit.

    It's not very common to cancel a task that will run for one second or less because it's a simple http request.
     
  21. GeorgeAdamon

    GeorgeAdamon

    Joined:
    May 31, 2017
    Posts:
    48
    Hello and thanks for your efforts!
    Are there any news on the new Instagram Graph API integration?
     
  22. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    I'm still working on it. You need to understand that it's a full rewrite of the existing API it's like another different asset that I will be give for free for existing customers. I'm trying to publish a new version before the end of the summer.

    I'm not rushing it because there are many Graph API's that are still only for closed beta testing for selected Facebook/Instagram partners so even if I publish it, you won't be able to use it yet.
     
  23. eunje_unity

    eunje_unity

    Joined:
    Jul 13, 2018
    Posts:
    2
    Hello, I have one question before i buy this asset!
    Can I set Hashtag by your asset?
     
  24. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    I don't really understand what you mean by that. Hastag to a media content? Instagram doesn't allow to post with the current API.

    And please check my online docs because there you have the available API.
     
  25. rtr989

    rtr989

    Joined:
    May 21, 2016
    Posts:
    3
    Hello! does your asset still work? insta made some changes in their api...
     
  26. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    You can check this information to see what is still working. Many APIs will work until 2020.
    • Public Content - all remaining capabilities to read public media on a user's behalf on December 11, 2018
    • Basic - to read a user’s own profile info and media in early 2020.
    https://www.instagram.com/developer/

    I'm also working (rewriting the code) on the replacement that it's Instagram Graph API but it is business oriented at least now .they are saying that they are going to provide in 2019 non business APIs.
     
  27. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    518
    Hey,

    We are using Firebase service in our project, and potentially it allows to use custom authentication using Instagram. Unfortunately there is nothing about Unity implementation, only this
    I got some questions relating to this case:
    1. will this asset provide auth token as a response?
    2. do someone have any experience of Unity + Firebase + this asset implementation? Is that possible at all?
    Thanks in advance
     
  28. kd_unity

    kd_unity

    Joined:
    Dec 19, 2018
    Posts:
    5
  29. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    With this asset no, I'm developing and testing a new asset that it's compatible with the new API.
     
    kd_unity likes this.
  30. kd_unity

    kd_unity

    Joined:
    Dec 19, 2018
    Posts:
    5
    can we still use it for Login using Instagram ?
     
  31. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    Of course.

    Some endpoints have been removed (due to the Facebook scandal some months ago) but there are still some of them that will work until at least 2020.

    That's why I'm working on the replacement that is Instagram Graph API. The problem is that now it's a business oriented API. That will change this year:

    "Support for Non-Business Profiles [FUTURE]: Basic permissioning for non-business profiles will be supported in early 2019."

    Source: https://developers.facebook.com/blog/post/2018/01/30/instagram-graph-api-updates/

    That's what I'm waiting for.
     
    kd_unity likes this.
  32. kd_unity

    kd_unity

    Joined:
    Dec 19, 2018
    Posts:
    5
    Hi N3uRo,

    How i can get the access token For iOS or Android?
    I'm want only use login for get access token and then close the web view.
     
    Last edited: Jan 24, 2019
  33. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    I don't understand your question. This asset will open a native WebView (Android or iOS), listen for a specific url redirect to obtain the access token and then close the WebView.

    Once you have the token, you can start to use each endpoint.
     
  34. jazzykhanx

    jazzykhanx

    Joined:
    Apr 11, 2018
    Posts:
    6
    Hi, I have few questions?
    I read the full documents but can't find the answers.
    1: Is it still working?
    2: is this works with opening app and giving permissions? because i dont need to put my password and username because users don't trust that now.
    3: If it works with opening app and giving permission how will i get the access token and user will close the instagram app manually right?
    thanks
     
  35. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    1. Yes, see this post: https://forum.unity.com/threads/rel...iented-event-based.377253/page-2#post-4132888.
    2. Yes, it opens the official facebook login page (you don't store user sensitive data on your own).
    3. That data it's store by my API internally you don't need to retrieve any token on your own. You also don't need the official app installed to use my asset.
     
  36. jazzykhanx

    jazzykhanx

    Joined:
    Apr 11, 2018
    Posts:
    6
    Hmmm, ThankYOU so if i add this to my script according to your documents, What i want is that it redirects user to the instagram app where they will give permissions and once they give it i want to know the current username etc.
    I dont want my users to put username and password in a webview is that possible right>
     
  37. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    That's right.

    Permissions are given from instagram official page (from a webview) not app but yes that's the workflow.
     
  38. pavel_shchelkun_ilogos

    pavel_shchelkun_ilogos

    Joined:
    Oct 31, 2017
    Posts:
    4
    Hello, we purchased this plugin for one of our projects. Works great on both iOS and Android devices. The only thing that is missing at the moment is logout. Even if we remove access token from PlayerPrefs, it seems that it automatically logins with last user anyway. The cache seems to be in the web view part, and at the moment we have been unable to find a way to solve this problem.

    Update

    With InAppWebBrowser plugin it is possible to clear web view cache and thus doing a full logout.

    But it would be better to have it in Instagram API plugin anyway.
     
    Last edited: Mar 6, 2019
  39. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    I've checked InAppWebBrowser plugin and I see that you have "InAppBrowser.ClearCache()" method. I hope that calling that fixes this issue, I know that depending on another asset it's not the best solution but I least you have one.

    I don't have that method in my asset because no one has asked that previously, I'm sorry. I can do it but I can't give you an ETA so if you are in a hurry use it in combination of that asset.
     
  40. Rob_Elias

    Rob_Elias

    Joined:
    Mar 21, 2014
    Posts:
    15
    Hello @N3uRo
    My company bought the asset last week and I am studying it. Can you tell me how to access the recent media links to place them in sprite? Leave me an example of the code if you can because I do not understand how to use GetUserRecentMedia ()
    Thank you
     
  41. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    Have you checked Example scene? Have you checked "UsersCategory" script? Please, tell me if you have any doubts.

    Thanks.
     
  42. cam415

    cam415

    Joined:
    Mar 26, 2014
    Posts:
    46
    Hi @N3uRo, I am thinking of purchasing his asset.
    1. Is it still possible to retrieve the data of getting a new "follower" (the number of "followers)
    2. Is it still possible to retrieve the data of a post getting a new "like" (the number of "likes")

    Thank you
     
    Last edited: Mar 19, 2019
  43. marauderkr

    marauderkr

    Joined:
    Jun 10, 2014
    Posts:
    46
    Greetings,
    I have a question about the plugin.
    1) Is it possible to make search queries like "search for apple" and return the results, i.e. instagram apple pages?
    2) Is it possible to get media from other public pages (not your own page) and download them? like images from an apple instagram page.
     
  44. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    You can make the requests available on this page:

    https://www.instagram.com/developer/endpoints/
     
    marauderkr likes this.
  45. ramkesh

    ramkesh

    Joined:
    May 15, 2019
    Posts:
    10
  46. Gangsta-Geek

    Gangsta-Geek

    Joined:
    Aug 11, 2012
    Posts:
    32
    I just purchased this plugin and I am wondering if there's been any updates that were requested and if its using the new API?