Gemini API Integration Expert Needed
Budget / Salary$250–750
TypeFreelance project
LocationRemote
Posted1 hour ago
using System;
using System.Text;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class GeminiService : MonoBehaviour
{
private string apiKey = "YOUR_GEMINI_API_KEY"; // أدخل مفتاح API الخاص بك هنا
private string apiUrl = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=";
[Serializable]
private class GeminiRequest { public Content[] contents; }
[Serializable]
private class Content { public Part[] parts; }
[Serializable]
private class Part { public string text; }
public IEnumerator SendPrompt(string userPrompt, Action callback)
{
string fullUrl = apiUrl + apiKey;
GeminiRequest requestData = new GeminiRequest
{
contents = new Content[]
{
new Content { parts = new Part[] { new Part { text = userPrompt } } }
}
};
string jsonPayload = JsonUtility.ToJson(requestData);
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonPayload);
using (UnityWebRequest request = new UnityWebRequest(fullUrl, "POST"))
{
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
request.downloadHandler = new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.Success)
{
callback?.Invoke(request.downloadHandler.text);
}
else
{
callback?.Invoke("خطأ في الاتصال بـ Gemini: " + request.error);
}
}
}
}
using System.Text;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class GeminiService : MonoBehaviour
{
private string apiKey = "YOUR_GEMINI_API_KEY"; // أدخل مفتاح API الخاص بك هنا
private string apiUrl = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=";
[Serializable]
private class GeminiRequest { public Content[] contents; }
[Serializable]
private class Content { public Part[] parts; }
[Serializable]
private class Part { public string text; }
public IEnumerator SendPrompt(string userPrompt, Action callback)
{
string fullUrl = apiUrl + apiKey;
GeminiRequest requestData = new GeminiRequest
{
contents = new Content[]
{
new Content { parts = new Part[] { new Part { text = userPrompt } } }
}
};
string jsonPayload = JsonUtility.ToJson(requestData);
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonPayload);
using (UnityWebRequest request = new UnityWebRequest(fullUrl, "POST"))
{
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
request.downloadHandler = new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.Success)
{
callback?.Invoke(request.downloadHandler.text);
}
else
{
callback?.Invoke("خطأ في الاتصال بـ Gemini: " + request.error);
}
}
}
}
Apply on Freelancer →
Project sourced from Freelancer.com. Applications happen directly on the original platform — we never collect your data.