andrewmd5 / InstaSharp

A C# Library that uploads images to Instagram.
56 stars 13 forks source link

Error at configuration system #3

Open msalah85 opened 7 years ago

msalah85 commented 7 years ago

Show me the following exception error: The current configuration system does not support user-scoped settings

please help me

pyxze commented 7 years ago

Try going to Properties -> Settings for the solution and change any items that have User for scope to Application.

msalah85 commented 7 years ago

Thanks for your replying,

I solved it by using appSettings in app.config file like this:

<appSettings>
    <add key="deviceId" value=""/>
    <add key="guid" value=""/>
  </appSettings>

Read/write from/on these properties using the following c# class:

using System.Configuration;
using System.Web.Configuration;

namespace InstaSharp
{
    public class AppSettingsManager
    {
        public static string ReadSetting(string key)
        {
            try
            {
                var appSettings = ConfigurationManager.AppSettings;
                string result = appSettings[key] ?? "Not Found";
                return result;
            }
            catch (ConfigurationErrorsException)
            {
                return "";
            }
        }

        public static void AddUpdateAppSettings(string key, string value)
        {
            try
            {               
                var configFile = WebConfigurationManager.OpenWebConfiguration("~");
                var settings = configFile.AppSettings.Settings;

                if (settings[key] == null)
                {
                    settings.Add(key, value);
                }
                else
                {
                    settings[key].Value = value;
                }
                configFile.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
            }
            catch (ConfigurationErrorsException ex)
            {
                throw ex;
            }
        }
    }
}

Making Updates in InstagramUploader.cs file after line no. 93 as:

               string guid;
                string deviceId;

                //save our device/guid so we look like we're always uploading from the same phone
                string currentDeviceIDValueToCheck = AppSettingsManager.ReadSetting("deviceId");

                if (!string.IsNullOrEmpty(currentDeviceIDValueToCheck)) 
                {
                    guid = AppSettingsManager.ReadSetting("guid");
                    deviceId = currentDeviceIDValueToCheck;
                }
                else
                {
                    guid = GenerateGuid();
                    deviceId = $"android-{guid}";

                    // 4 web app
                    AppSettingsManager.AddUpdateAppSettings("deviceId", deviceId);
                    AppSettingsManager.AddUpdateAppSettings("guid", guid);

                    // 4 desktop app
                    //Settings.Default.deviceId = deviceId;
                    //Settings.Default.guid = guid;
                    //Settings.Default.Save();
                }

This helped me to posting to my Instagram page by your website

Thanks

andrewmd5 commented 7 years ago

Hi @msaah85

If you submit a pull request I'd be happy to merge.

msalah85 commented 7 years ago

I set some updates on this API:

Of course I`m ready to push all updates that i have to you @Codeusa .