Code Monkey home page Code Monkey logo

Comments (7)

TheM4hd1 avatar TheM4hd1 commented on June 4, 2024

It's possible now to pass your own request headers or turn the default user-agent off.
It's accessible from: HttpSettings.shared.useFakeUserAgent = false

Note: a user agent is automatically provided as part of the default session configuration but it's awful, better to use your own customized one.

Read this link for more details

from swiftyinsta.

wojczitsu avatar wojczitsu commented on June 4, 2024

When I set useFakeUserAgent = false and try to login, I get error 'CSRF token missing or incorrect'. Please help :)

from swiftyinsta.

TheM4hd1 avatar TheM4hd1 commented on June 4, 2024

I took a look and it seems Instagram validates your user-agent before giving you a CSRF token.
User-Agent should follow this format:

Instagram [AppVersion] [OS] ([OSVersion]/[OSRelease]; [DPI]; [DeviceResolution]; [DeviceBrand]; [DeviceModel]; [DeviceModel]; [DeviceModelBoot]; [UserLocale]; [Facebook User-Agent escape string])
Instagram 78.0.0.9.103 Android (21/5.0.2; 480dpi; 1080x1776; Sony; C6603; C6603; qcom; ru_RU; 95414346)

It takes time to create a random user-agent generator but I think I will probably implement it.
There is a list of devices with info which you can create your own customized user-agent for now.
take a look at AndroidDeviceGenerator.swift

from swiftyinsta.

TheM4hd1 avatar TheM4hd1 commented on June 4, 2024

for now, you can use CustomUserAgent model to create your own user-agent like this:

let userAgent = CustomUserAgent(apiVersion: "79.0.0.0", osName: "iOS", osVersion: "12", osRelease: "1.4", dpi: "458", resolution: "2688x1242", company: "Apple", model: "iPhone11,2", modem: "intel", locale: "en_US", fbCode: "95414346")
HttpSettings.shared.addValue(userAgent.toString(), forHTTPHeaderField: "User-Agent")

If there is no further question, please close the issue.

from swiftyinsta.

cprovatas avatar cprovatas commented on June 4, 2024

@TheM4hd1
FYI:

let userAgent = CustomUserAgent(apiVersion: "79.0.0.0", osName: "iOS", osVersion: "12", osRelease: "1.4", dpi: "458", resolution: "2688x1242", company: "Apple", model: "iPhone11,2", modem: "intel", locale: "en_US", fbCode: "95414346")

won't work outside of framework scope because synthesized initializer is set to internal access by default

from swiftyinsta.

TheM4hd1 avatar TheM4hd1 commented on June 4, 2024

use the latest update.

public init(apiVersion: String, osName: String, osVersion: String, osRelease: String, dpi: String, resolution: String, company: String, model: String, modem: String, locale: String, fbCode: String) {

As you see the initializer is public

from swiftyinsta.

TheM4hd1 avatar TheM4hd1 commented on June 4, 2024

@cprovatas
Here is a function for creating user-agent base on device.

public static func build() {
        let device = HandlerSettings.shared.device!
        let apiVersion = "85.0.0.21.100"
        let os = "Android"
        let version = device.frimwareFingerprint.split(separator: "/")[2].split(separator: ":")[1]
        let androidVersion = AndroidVersion.fromString(versionString: String(version))
        if let androidVersion = androidVersion {
            let _androidVersion = androidVersion.versionNumber.split(separator: ".").first!
            let _androidRelease = androidVersion.versionNumber.split(separator: ".").last!
            let dpi = "640dpi"
            let res = "1440x2560"
            let company = device.deviceBrand
            let model = device.deviceModel
            let modem = device.deviceModelBoot
            let locale = "en-US"
            let fbCode = "146536611"
            let agent = CustomUserAgent(apiVersion: apiVersion, osName: os, osVersion: String(_androidVersion), osRelease: String(_androidRelease), dpi: dpi, resolution: res, company: company, model: model, modem: modem, locale: locale, fbCode: fbCode)
            HttpSettings.shared.addValue(agent.toString(), forHTTPHeaderField: Headers.HeaderUserAgentKey)
        }
    }

But I doubt that the issue is relevant to user-agent.

from swiftyinsta.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.